使用 git 签出文件时,如何找出导致文件权限更改的原因?

How to find out what causes file permissions to change when checking out files with git?

将文件推送到我们的服务器后,将执行以下 post-接收挂钩:

#!/bin/sh
export GIT_WORK_TREE=/home/user/www/
git checkout -f

但是,文件在签出时获得非常奇怪的 600 权限,文件夹 700。这不是我所期望的(在我们的其他服务器上,我们得到 644755)。从this thread了解到git没有设置权限,所以git无可厚非。我的问题是:什么是?我怎样才能找出这个问题的原因?

我已经通过 运行 一个额外的脚本在结账时临时解决了它来修复权限,但我有兴趣解决根本原因。

我正在使用 gitolite 来管理存储库,但我怀疑这就是原因。但同样,我很高兴知道我可以从哪里开始,因为此时我不确定如何对此进行调查。

根据最初的回答,我查看了服务器上的 umask 设置。 git 用户(即用于上传文件的用户),umask 设置为 0002。这在以下练习中得到确认:

git@server:~$ umask
0002
git@server:~$ touch newfile
git@server:~$ ls -la newfile
-rw-rw-r-- 1 git git 0 Aug  5 10:46 newfile

其他详细信息:

如“Git change default umask when update file”,你能把 umask 添加到你的 hook 中吗?

#!/bin/sh
umask 002
export GIT_WORK_TREE=/home/user/www/
git checkout -f

应该将文件权限设置为 664,将目录权限设置为 775。


关于 gitolite 具体而言,check the umask section of the gitolite.rc file:

$UMASK, octal, default 0077

The default UMASK that gitolite uses gives rwx------ permissions to all the repos and their contents.
People who want to run gitweb (or cgit, redmine, etc) realize that this will not do.

The correct way to deal with this is to give this variable a value like 0027 (note the syntax: the leading 0 is required), and then make the user running the webserver (apache, www-data, whatever) a member of the 'git' group.

If you've already installed gitolite then existing files will have to be fixed up manually (for a umask or 0027, that would be chmod -R g+rX). This is because umask only affects permissions on newly created files, not existing ones.

However, files get a very odd 600 permission, and folders 700 upon checkout.

看起来你的 shell 有一个限制性的 umask 设置,可能 umask 0177

From this thread I understand that git does not set permissions, so git is not to blame.

不,这是您 shell 的 umask 设置。

My question is: [...] [how] can I figure out what the cause is of this issue?

运行 umask,它会告诉你当前的设置是什么。就像 0177 或类似的。 如果你想知道为什么, 您需要查看 /bin/sh 使用的 rc 文件, 最有可能 .profile.bashrc,以及其他来源的文件。

您可以有非常严格的 umask 设置,但可以在脚本中覆盖它们,方法是按照@VonC 的建议添加 umask 行。