16

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
Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407

3 Answers3

16

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.

Zombo
  • 1
  • 62
  • 391
  • 407
torek
  • 448,244
  • 59
  • 642
  • 775
  • 4
    Not entirely sure how git actually implements it. I'd have to go dig into the source code. Ah, there it is: it depends on the git build-time configuration item `NO_TRUSTABLE_FILEMODE`. If that's not defined, it then tests at runtime by chmod-ing `.git/config` which it eventually replaces with `.git/config.lock` which wipes out its temporary chmod. The temporary version has the u+x bit set; if it stays set after chmod, git believes that the x bit matters. – torek Apr 30 '12 at 00:14
  • this makes perfect sense, but nonetheless is frustrating, I had to copy a project from one computer to another 5 times until I realized what's going on)) thanks! – Eugene Kuzmenko Nov 29 '13 at 12:09
  • 3
    Thanks,I know `git config --global core.fileMode false` is useless. git fileMode problem I had met it every day.I had to config that stuff every times I create a new project. – bronze man Oct 24 '14 at 05:42
  • In my case its the other way around. After a clone the local .git/config file contains: [core] filemode = false . Any idea why it determine it should be false (using git bash for windows on windows 10)?? – u123 Sep 19 '19 at 19:07
  • @u123: Git's test is: chmod `.git/config` to +x if it was -x, or -x if it was +x. Then check to see if the change actually took place. If so, the new replacement `.git/config.lock` file acquires a `filemode = true` line. If not, the new replacement `.git/config.lock` file acquires a `filemode = false` line. When config is done, it renames `.git/config.log` to `.git/config` and the new filemode setting is set. – torek Sep 19 '19 at 19:21
  • Since you're getting `filemode = false`, Git's attempt to chmod the file failed: it was +x and stayed +x, or it was -x and stayed -x. – torek Sep 19 '19 at 19:22
  • @u123 If actual chmod-ing works, though, this implies that your Git binary was built with the `NO_TRUSTABLE_FILEMODE` option, which simply replaces the "test at clone / init time" with "unconditionally set to false". To fix this you'll need to build (or obtain) a new Git binary, one not built with the option. – torek Sep 19 '19 at 19:38
4

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.

ZeroG
  • 507
  • 4
  • 8
0

(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
Tanguy
  • 2,227
  • 1
  • 18
  • 8