Git ignoring gitconfig?

Deadly 提交于 2019-11-30 08:25:02

问题


It appears Git is ignoring ~/.gitconfig

$ git config --global core.filemode false

$ git config -l
core.filemode=false
core.filemode=true

So now there are 2 entries for core.filemode and git is still not ignoring filemode changes

$ touch modetest

$ git add .

$ git commit -m test1
[master (root-commit) 320cfe4] test1
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 modetest

$ chmod +x modetest

$ git diff
diff --git a/modetest b/modetest
old mode 100644
new mode 100755

Based on torek’s answer, I added this line to my .bash_profile

[ -d .git ] && git config core.filemode false

回答1:


Maybe a bit overkill, but in Cygwin this bothered me enough to dig into the issue more. When git is built from source code, it checks the file system it's built on to see if it understands executable bits.

I went ahead and built git from source on my Cygwin system and installed it to a local directory, then added the binary to my path. The basic steps are:

cd ~/
mkdir git
cd git
mkdir inst
git clone -c core.autocrlf=false https://github.com/git/git.git
cd git
NO_TRUSTABLE_FILEMODE=1 make prefix=/home/[username]/git/inst/
NO_TRUSTABLE_FILEMODE=1 make prefix=/home/[username]/git/inst/ install

Then add something like this to .bashrc:

export PATH=/home/[username]/git/inst/bin:$PATH

Of course, that build won't work unless you have all the build dependencies installed in Cygwin. With a little poking around I was able to do it without too much trouble. Now git init and git clone on that system defaults filemode to false. The trick is defining NO_TRUSTABLE_FILEMODE for the build.




回答2:


When creating or reinitializing a new repo, git init always sets a new value for core.filemode based on the result of probing the file system. You'll just have to manually:

git config core.filemode false

Or:

git config --unset core.filemode

to make it respect the one in your ~/.gitconfig. If you run git init again the per-repo setting will go back to true on your system.




回答3:


(EDIT) so to resume, on windows we need to do :

git config --global --unset core.filemode
git config --unset core.filemode
git config core.filemode false

And you can create an empty config file in Git install dir for new git folders (init) :

C:\bin\Git\share\git-core\templates>echo > config
C:\bin\Git\share\git-core\templates>notepad config

And put inside :

[core]
filemode = false


来源:https://stackoverflow.com/questions/10376913/git-ignoring-gitconfig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!