git合并裸仓库中的分支 [英] git merging branches in a bare repository

查看:66
本文介绍了git合并裸仓库中的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 git 存储库创建以下设置:

I would like to create the following setup for my git repos:

我目前有一个包含我所有工作文件的本地 git 存储库.我希望能够设置一个中央裸存储库和另外两个非裸存储库——一个用于实时应用程序,另一个用于测试版本.

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.

所以在这个方案中,testing repo 总是从 testing 分支拉取,live repo 总是从 master 分支拉取.

So in this scheme, testing repo will always pull from testing branch, and live repo will always pull from the master branch.

不过,我不知道如何在裸存储库中合并分支.如果没有工作树,git-merge 和 git-checkout 似乎无法工作.

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:

  1. 是否有一种标准方法可以在裸存储库中合并分支?
  2. 这难道不是因为我的回购设置很差吗?(在这种情况下,您将如何修改此架构以获得最佳实践?)

推荐答案

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? And git 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.

这篇关于git合并裸仓库中的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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