Search code examples
gitcygwin

What are the consequences of git config core.filemode false?


For context, I'm experiencing this and trying to solve it: Git in Visual studio code says file is modified even when there is no change I am using cygwin on a Windows 10 machine, but all my coworkers are using macs.

The highest voted answer says to git config core.filemode false, but I can't figure out the consequences of doing that. Is it safe? Does it mean if I create a shell script, pushing it will lose the executable bit? Does it mean when I pull a new executable, it will lose the executable bit? What are the gotchas, if any?

I've checked the documentation, but it doesn't answer that question either, it just explains when you'd need to change it.


Solution

  • It seems that git only cares about the executable bit, so a file in git could only be 644 or 755. source code

    I've just done a test:

    $ mkdir test && cd test && git init
    $ touch before && chmod a+x before && git add before && git commit -m 'before' && git ls-tree HEAD
    
    > [master (root-commit) 1cb9c41] before
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100755 before
    100755 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    before
    
    $ git config core.fileMode false
    
    $ touch after && chmod a+x after && git add after && git commit -m 'after' && git ls-tree HEAD
    
    > [master b4d7a48] after
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 after
    100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    after
    100755 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    before
    

    As you can see, before the core.fileMode change, git keeps the file's executable bit(0755), while after the change, newly created files lost the executable bit(0644), while old files keep the old executable bit.

    So, in summary:

    With git config core.filemode false, git ignores the executable bit change on the local repository. Since git only cares about the executable bit, this won't lead to a 0000 file, but a 0644 file.

    Does it mean if I create a shell script, pushing it will lose the executable bit?

    Yes

    Does it mean when I pull a new executable, it will lose the executable bit?

    It depends on your file system. Some file systems such as NTFS change every files' permission to 0777 while others may lose the executable bit.