如何从另一个具有不同历史记录的存储库中重新提交提交? [英] How to rebase commits from another repository with a different history?

查看:51
本文介绍了如何从另一个具有不同历史记录的存储库中重新提交提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两个Git存储库.

We have two Git repositories.

回购1.提交:A,B,C.此存储库是根据SVN历史记录创建的.

Repo 1. Commits: A, B, C. This repository was created from SVN history.

回购2.提交:D,E,F.创建此存储库时没有SVN历史记录,只是使用了成为提交D的工作副本(从提交C开始).换句话说,提交的文件树C和D都一样.

Repo 2. Commits: D, E, F. This repository was created without SVN history, just by using the working copy (as of commit C) which became the commit D. In another words, the file trees of the commits C und D are the same.

现在,我们要合并两个存储库,因此我们在一个存储库中拥有完整的历史记录.有没有一种方法可以将所有提交的E..F复制/变基/其他"到C上?

Now, we want to merge both repositories so we have the full history in one repository. Is there a way to "copy/rebase/something else" all the commits E..F onto C?

推荐答案

最简单的方法是将 Repo 2 添加为樱桃选择提交 E 并在 C 顶部的 F .

The easiest thing to do would be to add Repo 2 as a remote in Repo 1 using its physical path on disk and then simply cherry pick commits E and F on top of C.

因此,在回购1 中,您将执行以下操作:

So, in Repo 1 you would do:

git remote add repo2 C:\Path\To\Repo2
git fetch repo2

然后,假设 E F Repo 2 master 分支中的最新两次提交,并且 C Repo 1 master 中的最新提交,如下所示:

then, assuming E and F are the latest two commits in the master branch in Repo 2 and C is the latest commit in master in Repo 1, like this:

      master
     /
A-B-C
      repo2/master
     /
D-E-F

您会这样做:

git checkout master
git cherry-pick repo2/master~2..repo2/master

将在 C 之上应用来自提交 E F 的补丁:

which will apply the patches from commits E and F on top of C:

           master
          /
A-B-C-E'-F'
      repo2/master
     /
D-E-F

请注意,这里我选择的是提交范围从Git 1.7开始受支持.2 .

Note that here I'm cherry-picking a range of commits, which is supported since Git 1.7.2.

这篇关于如何从另一个具有不同历史记录的存储库中重新提交提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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