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

后端 未结 11 1244
天命终不由人
天命终不由人 2020-11-22 02:29

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 pick

相关标签:
11条回答
  • 2020-11-22 02:50

    Adding to Greg Hewgill answer (of using core.fileMode config variable):

    You can use --chmod=(-|+)x option of git update-index (low-level version of "git add") to change execute permissions in the index, from where it would be picked up if you use "git commit" (and not "git commit -a").

    0 讨论(0)
  • 2020-11-22 02:51

    This works for me:

    find . -type f -exec chmod a-x {} \;
    

    or reverse, depending on your operating system

    find . -type f -exec chmod a+x {} \;
    
    0 讨论(0)
  • 2020-11-22 02:56

    If you want to set this option for all of your repos, use the --global option.

    git config --global core.filemode false
    

    If this does not work you are probably using a newer version of git so try the --add option.

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

    If you run it without the --global option and your working directory is not a repo, you'll get

    error: could not lock config file .git/config: No such file or directory
    
    0 讨论(0)
  • 2020-11-22 02:59

    If you want to set filemode to false in config files recursively (including submodules) : find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'

    0 讨论(0)
  • 2020-11-22 03:05

    You can configure it globally:

    git config --global core.filemode false

    If the above doesn't work for you, the reason might be your local configuration overrides the global configuration.

    Remove your local configuration to make the global configuration take effect:

    git config --unset core.filemode

    Alternatively, you could change your local configuration to the right value:

    git config core.filemode false

    0 讨论(0)
提交回复
热议问题