gpt4 book ai didi

当我推送到服务器时,Git 正在更改我的文件的权限

转载 作者:IT王子 更新时间:2023-10-29 01:15:20 25 4
gpt4 key购买 nike

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

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

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 文件夹内容在下面 - 而不是裸存储库。

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

这导致我在网络服务器上的代码出现困惑。

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

git 服务器配置文件

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

最佳答案

This thread post提供了一个很好的解释:

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 正在更改我的文件的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11230171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com