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

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

问题描述

我使用git来管理服务器上的网站。



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

  local @ workstation:myapp $ ls -l |对于(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职员340 5月14日15:22 system

服务器使用 post-receive 指向apache前面的回购站点。 Apache的 public 文件夹内容不在裸仓库中。

  root @server:/ srv / public / myapp#ls -l |对于(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 4096 Jun 27 11:31 system

这会导致混乱我的代码在网络服务器上。



我该如何解决这个问题?我使用的是gitolite,如果这有什么不同。



git服务器配置文件

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


解决方案

这篇文章提供了一个非常好的解释:


这是设计。虽然git数据结构在技术上可以在它的树中存储
unix模式位,但是在git的历史
中很早就发现,除了一个简单的可执行位之外,其他任何东西都被认为是
,对于git正常使用情况下(例如,将代码
或其他共享文件存储在存储库中的人员)。



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



如果模式对您很重要,则建议的修正为以下之一:使用像'metastore'这样的工具可以从git钩子调用,
将保存和恢复在
中存储的文件中的文件权限。请注意,在使用这样的工具时,在保护文件时有一个比赛
条件(即,git将创建文件为
644,然后Metastore将其更正为600;同时,
有人可以读你的文件)。

  • 根据你存储的内容,把你的仓库中的
    保存在另一个仓库中是有意义的目录,受权限保护以及
    ,然后使用单独的工具将文件从存储库
    部署到其最终位置(例如,Makefile或其他安装
    工具)。




  • 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
    

    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.

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

    git server config file

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

    解决方案

    This thread post offers a very good explanation:

    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).

    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. 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).

    2. 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天全站免登陆