Git changes the permissions on a single file unexplainably

[亡魂溺海] 提交于 2019-12-04 08:57:10
VonC

As mentioned in "Wrong file permission when using git pull in a hook"

Git does not store permissions, apart from the executable bit.
So, on checkout, files are created with the default permissions, which depend on your umask.

In your case: umask 0022 should be set when you are pulling.
(that is what I was mentioning in the answer you saw "Prevent Git from changing permissions on pull")

This assume that you have, in the target repo, a configuration like:

git config core.sharedRepository true

The other solution is mentioned in "How do I share a Git repository with multiple users on a machine?", where you would make sure to pull in a repo initialized like so:

git init --shared=0022

The OP Tom Haws adds in the comments:

Do you know why git at my client's production server is able to pull without having file permission changes even when there is no sharedRepository entry in that repository's config?

Maybe because umask was set by default to 0022 already, meaning that, by default, the git shell inherits the umask of the system.
Changing the umask requires a core.sharedRepository set to true to take it into account instead of taking the umask of the parent process.
That, or because the repo was created with --shared=0022.

To see how an umask can be set (system wide or user-wide), see "How to set system wide umask?"

To check an umask just before a git command (which would inherit its value), simply type:

umask
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!