当我推送到服务器时,Git 正在更改我的文件的权限 [英] Git is changing my file's permissions when I push to server

查看:20
本文介绍了当我推送到服务器时,Git 正在更改我的文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 git 来管理服务器上的网站.

I am using git to manage a website on a server.

我有一个如下所示的本地存储库

I have a local repository shown below

local@workstation:myapp$ ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
total 16
755 drwxr-xr-x@ 18 thomas  staff   612 Jun 13 15:35 application
755 drwxr-xr-x@ 11 thomas  staff   374 Jun 12 16:25 assets
644 -rw-r--r--@  1 thomas  staff  6399 Jun 22 11:45 index.php
755 drwxr-xr-x@ 10 thomas  staff   340 May 14 15:22 system

我在服务器上有一个裸存储库,它使用 post-receive 将存储库指向 apache.Apache 的 public 文件夹内容在下面 - 不是裸存储库.

I have a bare repository on the server that uses post-receive to point the repo in front of apache. Apache's public folders contents are below -not the bare repository.

root@server:/srv/public/myapp# ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
total 20
700 drwx------ 15 root root 4096 Jun 27 11:31 application
700 drwx------ 10 root root 4096 Jun 27 11:31 assets
600 -rw-------  1 root root 6399 Jun 27 11:31 index.php
700 drwx------  8 root root 4096 Jun 27 11:31 system

这对我在网络服务器上的代码造成了混乱.

This is causing mayhem to my code on the webserver.

我该如何解决这个问题?如果这有什么不同,我正在使用 gitolite.

How can I fix this? I'm using gitolite if that makes any difference.

git 服务器配置文件

git server config file

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true

推荐答案

这个帖子 提供了一个很好的解释:

This thread post offers a very good explanation:

这是设计使然.而 git 数据结构在技术上可以存储其树中的 unix 模式位,它是在 git 历史的早期发现的尊重任何超越简单可执行位的东西最终成为对于 git 的正常用例来说更麻烦(即人们存储代码或存储库中的其他共享文件).

This is by design. While the git data structure can technically store unix mode bits in its trees, it was found early on in git's history that respecting anything beyond a simple executable bit ended up being more cumbersome for git's normal use cases (i.e., people storing code or other shared files in a repository).

我们可以添加一个配置选项来尊重文件模式,但它有一般被认为不值得.只解决了一部分一般元数据问题,因为它省略了所有者和组名称或 ID,如以及 ACL 等扩展元数据.

We could add in a config option to respect file modes, but it has generally been seen as not worthwhile. It solves only a part of the general metadata problem, as it omits owner and group names or ids, as well as extended metadata like ACLs.

如果模式对您很重要,建议的修复是以下之一:

If modes are important to you, the suggested fixes are one of:

  1. 使用像metastore"这样的工具,可以从 git hooks 中调用,并且将在跟踪的文件中保存和恢复文件权限存储库.请注意,使用此类工具时会发生竞争保护文件的条件(即,git 会将您的文件创建为644,然后metastore会修正为600;同时,有人可以读取您的文件).

  1. Use a tool like "metastore" that can be called from git hooks, and will save and restore file permissions in a file that is tracked in the repository. Do note that when using such a tool there is a race condition in protecting files (i.e., git will create your file as 644, and then metastore will correct it to 600; in the meantime, somebody could read your file).

具体取决于您存储的内容,保留您在另一个目录中的存储库,受权限保护,以及然后使用单独的工具从存储库部署文件到它们的最终位置(例如,Makefile 或其他安装工具).

Depending on exactly what you're storing, it may make sense to keep your repository in another directory, protected by permissions, and then use a separate tool to deploy your files from the repository to their ultimate location (e.g., a Makefile or other install tool).

这篇关于当我推送到服务器时,Git 正在更改我的文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆