git - Git see other file permssion than my filesystem
问题描述
In git bash for windows 10 when I do:
$ ls -la
-rw-r--r-- 1 user 1049089 10 Jul 23 19:00 .gitignore
-rwxr-xr-x 1 user 1049089 28 Sep 19 15:47 a.sh*
-rwxr-xr-x 1 user 1049089 28 Sep 19 15:47 b.sh*
I can see that both a.sh
and b.sh
are executable. Also I have verified that by running both scripts - so from my filesystem point of view both of those files are executable.
But when I do:
$ git ls-tree HEAD
100644 blob c91cb20899da1dc6da1752f8b9cdc59e58e50873 a.sh
100755 blob c91cb20899da1dc6da1752f8b9cdc59e58e50873 b.sh
So from git perspective only b.sh
is executable which is also the case when I clone my repository on jenkins an try to execute the two scripts (only b.sh
is getting executed).
I have tried to: chmod +x a.sh
but git does not pick that up and just returns a status saying nothing to commit or nothing has been modified.
What is going on and how do I fix this?
UPDATE:
I now have:
$ git config -l | grep core
core.symlinks=true
core.autocrlf=false
core.fscache=true
core.editor='C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin
core.editor='C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession
core.autocrlf=false
core.preloadindex=true
core.fscache=true
core.filemode=true
Which makes sense since I have added core.filemode=true
in C:\Users\user\.gitconfig
:
...
[core]
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession
autocrlf = false
preloadindex = true
fscache = true
fileMode = true
...
But when I clone a new repository and run the same again from inside the repository I get:
$ git clone ssh://git@host/my-repo.git
..
$ cd my-repo
$ git config -l | grep core
core.symlinks=true
core.autocrlf=false
core.fscache=true
core.editor='C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin
core.editor='C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession
core.autocrlf=false
core.preloadindex=true
core.fscache=true
core.filemode=true
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
So it now lists two entries for core.filemode
. First one I guess is from the .gitconfig file from my user folder and the second one (set to false) seems to come from the file my-repo/.git/config
that contains:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
What determines what gets set in my-repo/.git/config
and why is that set to false?
Based on:
Git global core.fileMode false overridden locally on clone
and:
it seem I need to manully change .git/config after a clone for it to have any effect.
解决方案
您在 Windows 上设置为core.fileMode
gittrue
将跟踪执行位
# tell git to keep/ignore filemode (chmod) as change,
git config core.fileMode true/false
core.fileMode
告诉 Git 是否尊重工作树中的可执行文件位。
默认值为 true(当配置文件中未指定 core.filemode 时)。
How to update executable bit?
(就像你已经做过的那样)
# If you wish to set the executable bit use this command
git update-index --chmod=+x <file>
--chmod=(+|-)x
设置更新文件的执行权限。
推荐阅读
- c# - EWS 托管 API - 资源、已启用、共享
- node.js - 如何使用 HTTPOnly 访问服务器端的凭据?
- c - 涉及 getchar() 和 putchar() 的 C 简单代码意外输出
- r - 计算组中一点的密度
- python - 使用 Groupby 和 np.where 时,Pandas 应用与变换
- path - 将 Windows 路径添加回 WSL
- unity3d - OverlapBoxAll 2d 没有检测到任何东西
- r - 仅当行重复时才删除特定列中包含 NA 的行(基于其他两列)
- c++ - 当我包含 SoftTimer 库时,为什么 Arduino IDE 会给我一个编译错误?
- firebase - 使用 Firebase 流作为 Flutter 中另一个流的输入?