我有一个项目,开发时必须将文件模式更改chmod
为777,但不应在主存储库中更改它。
Git启动chmod -R 777 .
并标记所有文件为已更改。有没有办法让Git忽略对文件进行的模式更改?
尝试:
git config core.fileMode false
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 a 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).
该-c
标志可用于为一次性命令设置此选项:
git -c core.fileMode=false diff
并且该--global
标志将使其成为已登录用户的默认行为。
git config --global core.fileMode false
全局设置的更改不会应用于现有存储库。此外,git clone
并git init
明确设置core.fileMode
,以true
在回购的配置在讨论Git的全球core.fileMode假的克隆覆盖的地方
core.fileMode
这不是最佳做法,应谨慎使用。此设置仅覆盖mode的可执行位,不覆盖读/写位。在许多情况下,您认为您需要此设置,因为您做了类似的操作chmod -R 777
,使所有文件都可执行。但是在大多数项目中,出于安全原因,大多数文件不需要并且不应执行。
解决这种情况的正确方法是分别处理文件夹和文件权限,例如:
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
如果这样做的话core.fileMode
,除非在非常罕见的环境中,否则就不需要使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句