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

标签 git permissions gitolite

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

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

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

我已经通过在 checkout 时运行一个额外的脚本来修复权限来暂时解决了这个问题,但我有兴趣解决根本原因。

我正在使用 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

其他详细信息:

  • 在服务器端和开发端都使用 Linux
  • 在本地仓库中,权限为 755 和 644
  • 在 .git/config 中将 filemode 设置为 true

最佳答案

如“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。


具体关于 gitolitecheck 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.

关于git - 使用git checkout 文件时如何找出导致文件权限更改的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38789261/

相关文章:

gitolite 允许未经授权的用户

git - 为什么当我切换分支时 Git 不删除一些文件?

linux - 如何使用 curl.h 在我的网络服务器上安装 git 没有这样的文件错误

git - 使用 git ls-remote 显示除候选版本之外的所有标签

linux - 将 Linux 机器上的远程 Git 存储库克隆到 OS X 机器会导致文件具有 typechange 状态

python - 如何获取用户在 django guardian 中具有特定权限的所有对象?

ubuntu - Nginx(我认为)在请求太大时以错误的权限保存文件

linux - 删除 linux 文件。 -rwsrwsrwt(可能是rootkit)

git - 如何在 gitolite 中配置迁移的 git 存储库

git - 如何在当前 HEAD 和推送中的最新文件之间的预接收 Hook 中获取文件的 git diff?