Marcus Westin Marcus Westin - 1 year ago 208
Git Question

How do I make Git ignore file mode (chmod) changes?

I have a project in which I have to change the mode of files with

to 777 while developing, but which should not change in the main repo.

Git picks up on
chmod -R 777 .
and marks all files as changed. Is there a way to make Git ignore mode changes that have been made to files?

Answer Source


git config core.fileMode false

From git-config(1):

       If false, the executable bit differences between the index and the
       working copy are ignored; useful on broken filesystems like FAT.
       See git-update-index(1). True by default.

The -c flag can be used to set this option for one-off commands:

git -c core.fileMode=false diff

And the --global flag will make it be the default behavior for the logged in user.

git config --global core.fileMode false


core.fileMode is not the best practice and should be used carefully. This setting only cover the executable bit of mode and never the read/write bits. In many cases you think you need this settings because you did something like chmod -R 777, making all your files executable. But in most projects most files don't need and should not be executable for security reasons.

The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:

find . -t d -exec chmod a+rwx \; # Make folders traversable and read/write
find . -t f -exec chmod a+rw \;  # Make files read/write

If you do that, you'll never need to use core.fileMode, except in very rare environment.