如何将一个回购重新组合到另一个回购 [英] How to rebase one repo to another

查看:102
本文介绍了如何将一个回购重新组合到另一个回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 项目1:
Init --- A- --B --- C --- HEAD1

项目2:
初始--- D --- E --- F --- G --- HEAD2
有没有办法将Project 1(Init to HEAD)重新绑定到Project 2的Init提交,所以它看起来像这:

 项目1& 2:
A --- B --- C --- HEAD1
/
初始--- D --- E --- F --- G --- HEAD2

Project 1&项目2是相似的。主要区别在于它们的文件结构略有不同,如下所示:

  Project1:

MyProject /
File1
File2
File3

Project2:

MyParentProject /
MyProject /
File1
File2
File3
SomeFolder /
SomeOtherFolder /
... etc /

仅供参考:MyProject不是MyParentProject的子模块。 MyProject和MyParentProject作为两个单独的git存储库存在于两个不同的位置。 您可以将其中一个作为远程存储库。在Project1中,运行以下命令:

  git remote add project2< path_to_project_2> 
git fetch project2
git branch --track project2Branch project2 / master
git checkout project2Branch

使用git log查找该分支的初始提交(即Project2)的散列值。然后运行

  git checkout master#或任何你想要分支的分支
git rebase< hash-for-commit> ;

现在您已经使用Project2重塑了Project1。由于这听起来像是一次性操作,因此您只能使用一个存储库,您可以使用
$ b

  git远程rm project2 

现在您的主分支用Project2的初始化进行重新组装,而project2Branch已经完成Project2的历史。这有点破解,但它会做你想做的。

Let's say I have two different repositories like so:

Project 1:
Init---A---B---C---HEAD1

Project 2:
Init---D---E---F---G---HEAD2

Is there a way to rebase Project 1 (Init to HEAD) to the Init commit of Project 2 so it looks like this:

Project 1 & 2:
     A---B---C---HEAD1
   /
Init---D---E---F---G---HEAD2

The content of Project 1 & Project 2 are similar. The main difference is that their file structure is slightly different like so:

Project1:

MyProject/
    File1
    File2
    File3

Project2:

MyParentProject/
    MyProject/
        File1
        File2
        File3
    SomeFolder/
    SomeOtherFolder/
    ...etc/

FYI: MyProject is not a submodule of MyParentProject. MyProject and MyParentProject exist in two separate locations as two separate git repositories.

解决方案

You could treat one as a remote repository to the other. In Project1, run these commands:

git remote add project2 <path_to_project_2>
git fetch project2
git branch --track project2Branch project2/master
git checkout project2Branch

Use git log to find the hash for the initial commit of that branch (which is Project2). Then run

git checkout master # or whatever branch you want to rebase
git rebase <hash-for-commit>

You've now rebased Project1 with Project2. Since this sounds like a one time operation, where you'll then only be using the one repository, you can cleanup with

git remote rm project2

So now your master branch is rebased with the init of Project2, and project2Branch has the rest of the history of Project2. It's sort of a hack, but it will do what you want.

这篇关于如何将一个回购重新组合到另一个回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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