使用 Git 保留文件权限 [英] Retaining file permissions with Git

查看:48
本文介绍了使用 Git 保留文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照 我的 Web 服务器的版本控制中所述对我的 Web 服务器进行版本控制,通过从我的 /var/www 目录 创建一个 git repo.我希望我能够将 Web 内容从我们的开发服务器推送到 github,将其拉到我们的生产服务器,然后在池中度过剩下的一天.

I want to version control my web server as described in Version control for my web server, by creating a git repo out of my /var/www directory. My hope was that I would then be able to push web content from our dev server to github, pull it to our production server, and spend the rest of the day at the pool.

显然我计划中的一个问题是 Git 不会尊重文件权限(我还没有尝试过,现在只阅读它.)我想这是有道理的,因为不同的盒子可能有不同的用户/组设置.但是如果我想强制传播权限,知道我的服务器配置相同,我有什么选择吗?或者有没有更简单的方法来处理我想要做的事情?

Apparently a kink in my plan is that Git won't respect file permissions (I haven't tried it, only reading about it now.) I guess this makes sense in that different boxes are liable to have different user/group setups. But if I wanted to force permissions to propagate, knowing my servers are configured the same, do I have any options? Or is there an easier way to approach what I'm trying to do?

推荐答案

git-cache-meta 在 SO 问题git-如何恢复git认为文件应该是的文件权限?"(以及 git FAQ)是更直接的方法.

The git-cache-meta mentioned in SO question "git - how to recover the file permissions git thinks the file should be?" (and the git FAQ) is the more staightforward approach.

这个想法是将文件和目录的权限存储在 .git_cache_meta 文件中.
它是一个单独的文件,未直接在 Git 存储库中进行版本控制.

The idea is to store in a .git_cache_meta file the permissions of the files and directories.
It is a separate file not versioned directly in the Git repo.

这就是为什么它的用法是:

That is why the usage for it is:

$ git bundle create mybundle.bdl master; git-cache-meta --store
$ scp mybundle.bdl .git_cache_meta machine2: 
#then on machine2:
$ git init; git pull mybundle.bdl master; git-cache-meta --apply

所以你:

  • 捆绑您的存储库并保存相关的文件权限.
  • 复制远程服务器上的这两个文件
  • 在那里恢复存储库,并应用权限
  • bundle your repo and save the associated file permissions.
  • copy those two files on the remote server
  • restore the repo there, and apply the permission

这篇关于使用 Git 保留文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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