将具有不同树结构的更改从一个回购合并到另一个回购合并 [英] Merge changes from one repo to another with different tree structures

查看:107
本文介绍了将具有不同树结构的更改从一个回购合并到另一个回购合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Git仓库,foo / master和bar / master:

在foo中:

  code_root 
- > dirA
- > dirB
- > *一些文件*

栏内:

  code_root 
- > *与上面相同的文件*

现在有人对 * ...如何将这些更改合并到 *与上面相同的文件*



当我说合并时,我的意思是我需要delta的历史记录(提交消息,日志哈希等)来完成。

解决方案

您可以将更改拆分为子树级别,然后与其他分支合并:

 <$ c $ #>#你的foo项目
git subtree split --prefix = dirA / dirB / --branch = temp-branch [--onto =<在子注释1上] [< commit-sub- note2>]

到子笔记1 :看起来像 bar 项目完全存在,您必须在某个时间点复制它,并将其作为新库启动,在这种情况下,如果您希望在此之后做出所有更改,则可以指定 bar 在引入更改时提交id。



提交子注释2 :然后,您需要指定在首先复制子项目时使用的提交ID,以便您只获取自从然后合并到您已拥有的 bar 副本中(这将保留您错过的历史记录)。使用类似这样的语法将commit id本身包含到最新: 0abc210 ^ ..



您也可以使用 - 重新加入来提交到您的 foo 项目中,如果您希望继续开发在 bar 之后使用您的 foo 项目。提交到 foo 是一种毫无意义的事情,除了帮助子树命令基于它的拆分变化以后更容易变更。



运行后split命令,你将在 foo 的分支中,它只有这些文件。从那里你可以用你的 bar 项目进行正常合并,或者启动一个新项目并将 bar 合并到该项目中(因为它可能没有适当的历史记录)。您可能希望在尝试进行合并之前将其重设为分歧点。



编辑:此处还有 git subtree命令参考

I have two Git repos, foo/master and bar/master:

In foo:

code_root
->dirA
  ->dirB
    -> *some files*

In bar:

code_root
  -> *same files as above*

Now someone has made changes to *some files*... how do I get those changes merged into *same files as above*?

When I say "merged" I mean I need the history (commit messages, log hashes etc.) of the deltas to come over as well.

解决方案

You can split the changes out to the subtree level, and then merge with your other branch:

# from your foo project
git subtree split --prefix=dirA/dirB/ --branch=temp-branch [--onto=<onto-sub-note1>] [<commit-sub-note2>]

onto sub-note 1: It seems like since bar project exists at all, you must have copied it at some point in time, and started this as the new library, in which case, if you want all changes made after that, you'd specify this bar commit id when the changes were brought in.

commit sub-note 2: You'd then want to specify the commit id that was used when you copied the sub-project in the first place, so that you only get the changes since then to merge into the copy of bar you already have (this will maintain the history of what you missed). Use syntax like this to include the commit id itself up to the latest: 0abc210^..

You can also use --rejoin to make a commit back into your foo project, which will make it easier to push changes later if you would like to continue development on bar from withing your foo project. The commit back into foo is kind of pointless other than to help the subtree command base it's split changes more easily in the future.

After running the split command, you'll be in a branch of foo, which only has those files. From there you can do a normal merge with your bar project or start a new project and merge bar into that (since it probably doesn't have a proper history). You may want to rebase to the diverge point or something before trying to do that merge though.

Edit: Also here's the reference for git subtree commands

这篇关于将具有不同树结构的更改从一个回购合并到另一个回购合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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