git 合并裸存储库中的分支
我想为我的 git 存储库创建以下设置:
我目前有一个包含所有工作文件的本地 git 存储库。我希望能够设置一个中央裸存储库和另外两个非裸存储库——一个用于实时应用程序,一个用于测试版本。
我希望能够将测试分支上的更改从本地推送到中央裸存储库。然后,在我的测试存储库上,始终从裸存储库的测试分支中提取。
当准备好进行更改时,我希望能够将我的测试分支和主分支合并到中央裸存储库中。然后实时存储库可以从主分支拉取。
因此,在此方案中,测试存储库将始终从测试分支拉取,而实时存储库将始终从主分支拉取。
但我不知道如何合并裸存储库中的分支。如果没有工作树,git-merge 和 git-checkout 似乎无法工作。
所以,我的问题有两个:
- 是否有一种标准方法可以在裸存储库中合并分支?
- 这不是很直接吗,因为我的存储库的设置很差? (在这种情况下,您将如何修改此架构以获得最佳实践?)
I would like to create the following setup for my git repos:
I currently have a local git repo with all my working files. I would like to be able to setup a central bare repository, and two other non-bare repositories -- one for a live application and one for a testing version.
I would like to be able to push changes from local to the central bare repo on a testing branch. Then, on my testing repo, always pull from the testing branch of the bare repository.
When ready to go live with the changes, I would like to be able to merge my testing branch and my master branch in the central bare repository. Then the live repo could pull from the master branch.
So in this scheme, testing repo will always pull from testing branch, and live repo will always pull from the master branch.
I can't figure out how to merge branches in a bare repository though. git-merge and git-checkout don't seem to work without the working tree.
So, my question is two-fold:
- Is there a standard way to merge branches in a bare repo?
- Is this not straight-forward because the setup of my repos is poor? (In which case, how would you modify this architecture for best practices?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,这实际上可以在裸存储库上完成,但您必须使用正常的界面。
更新:从 git 2.38 开始,“git merge-tree”有一个新的模式来执行此操作,使用与“git merge”相同的机制。从联机帮助页的使用部分:
Note, this can actually be done on a bare repo, but you have to work around the normal interface.
Update: since git 2.38, "git merge-tree" has a new mode to do this, using the same machinery as "git merge". From the usage section of the manpage:
git checkout
将一个分支检出到工作树中——您认为如果没有工作树,这应该如何工作?并且 git merge 和大多数其他命令不起作用,因为裸存储库内没有 HEAD。回答你的问题:你不在裸存储库中工作。裸存储库仅用于保存数据;如果您想使用它,请使用非裸露的克隆。
因此,从任何其他存储库中,您可以从裸存储库中提取内容,在本地合并并将更改推送回其中。顺便说一句,您应该从您的开发存储库中执行此操作。以便实时和测试存储库仅从其分支中提取。
git checkout
checks out a branch into the working tree – how do you think this should have worked without a working tree? Andgit merge
and most other commands don’t work, because there is no HEAD inside of a bare repository.To answer your question: You don’t work within the bare repository. A bare repository is only there to keep the data; if you want to work with it, use a clone which is not bare.
So from any other repository, you pull from the bare repository, merge locally and push your changes back to it. You should do this from your development repository btw. so that the live and test repositories only pull from their branch.
您必须首先从裸存储库克隆,合并分支,然后再次推送到裸存储库。因为裸存储库上没有任何工作树来解决冲突。
You must first clone from bare repository, merge your branch, then push to bare repository again. Because you haven't any working tree on bare repositories for solve conflict.