如何将两个不同存储库中的两个分支合并到一个存储库中? [英] How to combine two branches from two different repositories in a single repository?

查看:120
本文介绍了如何将两个不同存储库中的两个分支合并到一个存储库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git仓库的结构如下所示:

  ABCDEF#master分支在单独的repo1中
ABCDEGH# master分支在单独的repo2

AH是简单的提交。正如你所看到的仓库是相关的(repo2是repo1的一个分支)。



之后,单个存储库应该具有以下结构:

  ABCDEF#以前的回购的master分支
\
\
GH#以前回购的master分支

我已经花了很多时间阅读Git用户指南等等。然而,这个(特殊的)使用情况似乎没有记录在任何地方。

与第一个远程仓库相同的文件系统。



首先,执行以下操作:

  git remote add< name> /path/to/other/repo/.git 
git fetch< name>
git分支<名称> < name> / master #optional

现在它们都在单个存储库中分支。你可以用git checkout在它们之间切换,用git merge合并等。


The structures of my Git repositories look like this:

A-B-C-D-E-F   # master branch in separate repo1
A-B-C-D-E-G-H # master branch in separate repo2

A-H are simple commits. As you can see the repositories are related (repo2 is a fork of repo1). I'm trying to combine these two repositories in one.

Afterwards the single repository should have the following structure:

A-B-C-D-E-F   # master branch of previous repo1
        \
         \
          G-H # master branch of previous repo2

I've already spent a lot of time reading the Git User's Guide and so on. However, this (special) case of use doesn't seem to be documented anywhere.

解决方案

You can treat another git repository on the same filesystem as a remote repo.

In the first, do the following:

git remote add <name> /path/to/other/repo/.git
git fetch <name>
git branch <name> <name>/master #optional

Now they're both branches in a single repository. You can switch between them with git checkout, merge with git merge, etc.

这篇关于如何将两个不同存储库中的两个分支合并到一个存储库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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