且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从另一个具有不同历史记录的存储库中重新提交提交?

更新时间:2023-01-19 12:26:01

最简单的方法是将 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.