简体   繁体   English

如何合并两个git存储库

[英]How to merge two git repositories

We have project, that was cloned into three independent repositories [ production , developer1 , developer2 ]. 我们有一个项目,该项目被克隆到三个独立的存储库中( 生产developer1developer2 )。

Developer repos are working like (bare+live). 开发人员存储库的工作方式类似于(裸机+实时)。

Each developer working with his own repo, and after some time, we desided to merge developers repos, to pull merged version into production. 每个开发人员都使用自己的存储库,过一段时间后,我们决定合并开发人员存储库,以将合并的版本引入生产环境。 After this, all tree repositories should be identical. 此后,所有树存储库应相同。

Is there any way to do this? 有什么办法吗?

Yes, that is the primary workflow. 是的,那是主要的工作流程。

You need to transfer all the branches you wish to merge to a single machine, and use the git merge command. 您需要将所有希望合并的分支转移到一台机器上,并使用git merge命令。 Afterwards, you end up with a single branch that is a strict successor of the other developers' branches, so they can fast-forward to the merged version. 之后,您将得到一个单独的分支,该分支是其他开发人员分支的严格后继者,因此他们可以快速前进到合并的版本。

What you want to do is to set up a remote for each of the developer's repos. 您要做的是为每个开发人员的存储库设置一个遥控器。 If you can't access them by network, ask for a copy of their .git folder and make a remote to a place on your harddrive that has it. 如果您无法通过网络访问它们,请索取他们的.git文件夹的副本,然后将其复制到硬盘驱动器上具有该文件夹的位置。 You should have as many remotes as you have developers. 您应该拥有与开发人员一样多的遥控器。 In your repo, git fetch each repo. 在您的仓库中, git fetch每个仓库。 If you named each remote by their names, like "johnsmith", you can now see each master branch from their repos. 如果您使用它们的名称(例如“ johnsmith”)来命名每个远程,则现在可以从其回购中看到每个master分支。 They will look like so: johnsmith/master , janedoe/master , etc. when you issue the git branch -r command to list all the remote tracking branches. 当您发出git branch -r命令列出所有远程跟踪分支时,它们将如下所示: johnsmith/masterjanedoe/master等。

Now you can merge those one by one with a command like 现在,您可以使用以下命令逐一合并这些命令

git merge orange/johnsmith

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM