我如何让Git忽略文件模式(chmod)更改? [英] How do I make Git ignore file mode (chmod) changes?

查看:213
本文介绍了我如何让Git忽略文件模式(chmod)更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,在开发过程中,我必须将 chmod 文件的模式更改为777,但在主要的回购库中不应更改。

Git选择 chmod -R 777。并将所有文件标记为已更改。有没有办法让Git忽略对文件进行的模式更改?

试试:

  git config core.fileMode false 

git-config(1)
$ b


  core.fileMode 
如果为false,则索引并且
的工作副本被忽略;对破碎的文件系统如FAT很有用。
请参阅git-update-index(1)。默认情况下为真。


-c flag可以用来为一次性命令设置这个选项:

  git -c core.fileMode = false diff 

- global 标志会使它是登录用户的默认行为。

  git config --global core.fileMode false 
code>



警告



core.fileMode 不是最佳做法,应谨慎使用。该设置仅涵盖模式的可执行位,而不涵盖读/写位。在许多情况下,你认为你需要这个设置,因为你做了类似于 chmod -R 777 的所有文件,使所有文件都可执行。但是在大多数项目中大多数文件不需要,也不应该出于安全原因可执行



解决这种情况的正确方法是分别处理文件夹和文件权限,如:

  find。 -type d -exec chmod a + rwx {} \; #使文件夹可以穿越并读/写
find。 -type f -exec chmod a + rw {} \; #Make files read / write

如果你这样做,你永远不需要使用 core.fileMode ,但在非常罕见的环境中。


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?

解决方案

Try:

git config core.fileMode false

From git-config(1):

core.fileMode
       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

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 separately, with something like:

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 do that, you'll never need to use core.fileMode, except in very rare environment.

这篇关于我如何让Git忽略文件模式(chmod)更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆