Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (29.3k points)

I have a project in which I have to change the mode of files with chmod 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?

1 Answer

0 votes
by (50.2k points)

For this, you can try the following command 

git config core.fileMode false

Please refer to core.fileMode documentation: https://git-scm.com/docs/git-config#Documentation/git-config.txt-corefileMode

There are several options like -c and --global

-c option is used  to set this option for one-off command

git config -c core.fileMode=false diff

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

git config --global core.fileMode false 

Changes in the global setting won't be applied to existing repositories. You have to either clone the repository again or execute git init. It will not overwrite things that are already there.

Warning

core.fileMode is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting 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 like this

find. -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write

find. -type f -exec chmod a+rw {} \;  # Make files read/write

If you follow this there is less chance of using core.fileMode.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...