旧提交和新提交在不同的存储库中,如何连接它们?

时间:2016-04-08 09:50:00

标签: git github version-control

我面临以下问题。

我想分叉一个托管在SourceForge上的旧软件。我这样做的方式很简单,我刚下载了最新版本的代码并将文件添加到git repo中。

因此,提交#987在我的git repo上提交#1。 然后我开始研究它。

然后,我已经意识到最好保留以前的开发者在SourceForge上做的旧提交的记录。

我设法将他们的回购转换为git。

因此,为了说明这一点,我现在有两个存储库。 Repo A是我创建的第一个,它只包含我的提交,但不包含开发人员之前提交的历史记录。 Repo B是SourceForge repo的svn to git转换。

我知道我可以将提交从repo A转移到repo B,因为A包含更新的提交。 但我想将旧的提交从回购B转移到回购A.

有可能吗?

1 个答案:

答案 0 :(得分:3)

AFAIU,最后,你想要一个包含所有提交的回购,包括新旧提交。

对我来说最简单的是:

  • 从包含旧提交的repo开始
  • 在这个旧仓库中添加一个遥控器,指向一个包含新提交的仓库,然后获取
  • cherry-选择包含旧提交的master分支上的新提交

所以基本上看起来像

cd old_repo
git remote add new ../new_repo
git fetch --all
# at this point we have two streams of commits with no common ancestor

#let's say you have 20 new commits, in a single branch
git cherry-pick new/master~20
git cherry-pick new/master~19
...
git cherry-pick new/master~1
git cherry-pick new/master
相关问题