如何设置GIT_DIR& GIT_WORK_TREE在维护多个存储库时 [英] How to set GIT_DIR & GIT_WORK_TREE when maintaining multiple repositories
问题描述
就像这个SO post ,我有以下的工作流程,我想用git来维护:
- 多人在本地开发 >
- 提交一些资讯
- 提交更多资讯
- 推送到分期付款
- 在测试中测试新代码
- 推送到产品
- 与每个命令一起输入目录和工作树的替代方法
- 将它们设置为持久性环境变量的替代方法,因为这只适用于网站1,而不适用于网站2,网站3等
我正确地处理这个问题吗?如何获得每个存储库所需的目录信息?
解决方案如果我理解正确,每个Web根目录的存储库。如果是这样的话,您可以在存储库级别设置工作树(在
.git / config
文件中):core.worktree
。如果回购配置为bare
:[core]
bare = false
worktree = / webroot / dir / for / this / repo
设置完成后,Git命令(如
git status
)应该再次从存储库文件夹中运行,并且所有使用工作树的命令(git status
,git checkout
等)将使用core.worktree
位置。 (请注意,Git命令仍然无法从工作树位置运行,因为它不是存储库。)Much like this SO post, I have the following workflow that i would like to maintain with git:
- Multiple people develop locally
- Commit a few things
- Commit more things
- Push to Staging
- Test new code on Staging
- Push to Production
Our staging server serves many different sites. I would like to set up the repository for each in a different folder in a user's home directory. Each repository will have a post-receive hook (ala the Daniel Messier article) that checks out the changes into the web root for that site/repository.
It's number six that is giving me trouble.
When I try to run any git commands, I get the error "fatal: This operation must be run in a work tree". I get this error whether I am running 'git status' from the repository (/home/gituser/website1.git - which I don't believe should work anyway..) or from the web root (/var/www/website1).
However, if I specify the GIT_DIR and GIT_WORK_TREE, then I am able to run git commands. Both of these work:
$ git --git-dir /home/gituser/website1.git --work-tree /var/www/website1 status $ GIT_DIR=/home/gituser/website1.git GIT_WORK_TREE=/var/www/website1 git status
So I need:
- An alternative to typing the directory and work tree along with every command
- An alternative to setting them as persistent environment variables, because that would only work for website1, not website2, website3, etc
Am I going about this correctly? How can I get git the directory info it needs for each repository?
解决方案If I understand correctly, you've got a different repository for each web root. If that's the case, you can set the work tree at the repository level (in the
.git/config
file):core.worktree
. It won't work if the repo is configured asbare
:[core] bare = false worktree = /webroot/dir/for/this/repo
Once that's set, Git commands (like
git status
) should work from the repository folder again, and any commands that use the work tree (git status
,git checkout
, etc.) will use thecore.worktree
location. (Note that Git commands still won't work from the work tree location, because it's not a repository.)这篇关于如何设置GIT_DIR& GIT_WORK_TREE在维护多个存储库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
。我想为每个用户的主目录中的不同文件夹设置存储库。每个存储库都会有一个post-receive挂钩(ala Daniel Messier文章),用于检查该网站/存储库的网站根目录发生了变化。
这是数字6给我带来的麻烦。
当我尝试运行任何git命令时,出现错误致命的:此操作必须在工作树中运行。无论我从存储库运行'git status'(/ home / gituser / website1.git - 我不认为应该可以工作),还是从web根目录(/ var / www / website1) 。然而,如果我指定了GIT_DIR和GIT_WORK_TREE,那么我可以运行git命令。这两个工作:
$ git --git-dir /home/gituser/website1.git --work-tree / var / www / website1 status
$ GIT_DIR = / home / gituser / website1.git GIT_WORK_TREE = / var / www / website1 git status
所以我需要: