如何将提交从一个分支复制到另一个分支 [英] How to copy commits from one branch to another

查看:76
本文介绍了如何将提交从一个分支复制到另一个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个功能

共享-提交-A-B-C Feat1

Shared -- Commits -- A -- B -- C Feat1

共享-提交-D-E-F Feat2

Shared -- Commits -- D -- E -- F Feat2

问题是要测试Feat2,我也确实需要Feat1,但是我仍然希望它们作为单独的分支,因为它们是不同的.是一种对Feat2进行更改,然后快速进行第三个分支的好方法,这两个分支在一起不需要我每次都销毁它.

The problem is that to test Feat2 I really need Feat1 as well, but I still want them as separate branches because they are distinct. What is a good way to make changes to Feat2 and then quickly make a third branch that is both of them together that doesn't require me to destroy it every time.

共享-提交-Feat1-Feat2

Shared -- Commits -- Feat1 -- Feat2

我在做什么

git checkout feat2 git branch -b combo git rebase -i feat1

git checkout feat2 git branch -b combo git rebase -i feat1

但是当我对feat2进行更新时,我不知道如何合并这些新更改.

But then when I make updates to feat2 I don't know how to merge in those new changes.

推荐答案

合并

您可以合并而不是重新设置基准.由于您的combo分支仅用于测试,因此您不必担心历史记录会更加混乱.

Merging

You can merge instead of rebase. Since your combo branch is just for testing, you don't have to worry about the history being a bit messier.

也就是说:

git checkout feat2
git branch -b combo
git merge feat1

稍后,当您更新feat2时:

Later, when you update feat2:

git checkout combo
git merge feat2

每当您对feat1或feat2进行更新时,请将其合并到组合中.

Whenever you make an update to feat1 or feat2, merge that into combo.

缺点是您必须合并两个分支中的所有提交.如果有不需要的更改,则必须进行单独的提交,以删除组合分支中的那些更改.

The disadvantage is that you'll have to merge all commits in both branches. If there are changes you don't want, you'll have to make a separate commit removing those changes in the combo branch.

您可以将feat2中的其他提交重新组合到组合上.

You can rebase the additional commits from feat2 onto combo.

假设您在feat2上添加了一些提交,然后将这些提交移动到组合:

Suppose you add some commits onto feat2, then to move these commits to combo:

git rebase --onto combo lastcommittoexcludeonfeat2 feat2

或者,在对feat2进行更改之前,添加一个分支或标签,例如:

Alternatively, before you make the changes to feat2, add a branch or tag, eg:

git checkout -b lastfeat2rebase
git checkout feat2
git commit ... # more commits here to feat2
git rebase --onto combo lastfeat2rebase feat2

请注意,一旦使用了rebase选项,就不能再使用merge选项.如果使用merge选项,则以后可以决定使用rebase选项.

Please note, that once you go with the rebase option, you cannot use the merge option anymore. If you use the merge option, you can later decide to go with the rebase option.

这篇关于如何将提交从一个分支复制到另一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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