Git repo 默认忽略文件权限

Git repo default ignore files permissions

前段时间在一个几个人开发的项目中工作。其中一个人有意无意地更改了 chmod 一些文件。当更改推送到存储库时,每次都会从那里下载代码,因为在开始时,许多文件被标记为 "changed"。我浪费了很多时间来寻找原因。

现在每次获取回购时我都会在终端中写入

git config core.fileMode false

忽略更改文件权限。 我知道我可以在全局 git 配置文件中设置它,但我会做更多的事情。我想在项目存储库中将此选项设置为默认选项,下载此存储库的每个人都将设置 git 配置以忽略文件权限。

知道如何达到那个目标吗?

Git 忽略可执行位以外的所有权限位 (换句话说,git 的树对象的文件和目录条目具有 755 或 644 的权限掩码——没有别的)。 core.fileMode 仅与可执行位有关。你通常希望那些可执行位得到尊重,除了一些奇怪的文件系统,在这种情况下,用户应该自己关闭 core.fileMode

来自git帮助配置:

core.fileMode Tells Git if the executable bit of files in the working tree is to be honored.

       Some filesystems lose the executable bit when a file that is marked as executable is checked
       out, or checks out an non-executable file with executable bit on.  git-clone(1) or git-init(1)
       probe the filesystem to see if it handles the executable bit correctly and this variable is
       automatically set as necessary.

       A repository, however, may be on a filesystem that handles the filemode correctly, and this
       variable is set to true when created, but later may be made accessible from another environment
       that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created
       repository with Git for Windows or Eclipse). In such a case it may be necessary to set this
       variable to false. See git-update-index(1).

       The default is true (when core.filemode is not specified in the config file).