如何将特征(在主题分支中)移植到另一个分支? [英] How to transplant a feature (in a topic branch) to another branch?
问题描述
master
和 experimental
。我在实验
的主题分支中做了一些工作,我为几个功能( feature1
, feature2
, feature3
)。如何将 feature2
中完成的工作移植到 master
? 我的初始库:
master
|
A-B-C
\
D-E I L P
\ / \ / \ / / |
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
我想要的存储库:
master
|
ABC ----------------------------- J'-K'
\
DE ILP
\ / \ / \ / |
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
我能想到的一个方法是 git结帐主人; git cherry-pick JK
但这很容易出错,主题分支可能有很多不同的提交。
我希望它能像 git checkout master; git< transplant-commits-in-topic-branch-into-current-branch> feature2
,但我熟悉的所有基础命令移植来自共同祖先的所有差异(在这种情况下 A
),我想要只移植 I
和 K
之间的差异,而不是混淆提交哈希。
有点背景:我正在研究一个代码库,这个代码库已经被分离出来了,但是我想提供某些功能。我开发了主题分支中的所有新功能,然后我将它们合并回主设备中。 解决方案
将 feature2
移动到 master
,并且'I'和'K'不取决于 feature1
,你可以将它移植到:
git rebase --onto master feature1 feature2
该语法可以松散地读为Rebase feature2
到 master
。它原来的上游是 feature1
。
然后,如果将 feature2
合并到 master
中,它将是一个快进合并。>
但是,如果 feature1
中的变化,将不在 master
上,整个情况变得更加复杂,你想要做什么完全取决于你的工作流程以及你如何与父项目相关联。挑选樱桃会起作用......只要你愿意让你的功能分支在原来的主人身上复杂化。或者你可以重新分配你所有的分支机构,使 feature2
对 feature2
(和 feature3
等等)off master
如果你能帮助它。它会为您节省很多麻烦。
Say I have 2 parallel long lived branches: master
and experimental
. And I do some work in a topic branch off of experimental
, and I do this for a couple features (feature1
, feature2
, feature3
). How would I transplant the work done in feature2
onto master
?
My initial repository:
master
|
A-B-C
\
D-E I L P
\ / \ / \ /|
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
My desired repository:
master
|
A-B-C-----------------------------J'-K'
\
D-E I L P
\ / \ / \ /|
F-G-H \ / \ / |
| J-K \ / experimental
feature1 | M-N-O
feature2 |
feature3
One way I can think of doing it is git checkout master; git cherry-pick J K
but that's error prone and the topic branch might have many different commits.
I would expect it to work something like git checkout master; git <transplant-commits-in-topic-branch-onto-current-branch> feature2
, but all of the rebasing commands I'm familiar with transplant all the diffs from the common ancestor (in this case A
), I want to transplant just the diffs between I
and K
, and not mess with commit hashes.
A bit of context: I'm working on a codebase which was forked off of an original, however I'd like to contribute certain features back. And I develop all the new features in topic branches which I then merge back into my master.
If you're just trying to move feature2
onto master
, and 'I' and 'K' don't depend on changes made in feature1
, you can transplant it with:
git rebase --onto master feature1 feature2
That syntax reads, loosely, as "Rebase feature2
onto master
. It's original upstream was feature1
."
Then if you merge feature2
into master
, it'll be a fast-forward merge.
If, however, feature2
depends on changes in feature1
that won't be on master
, the whole situation gets much more complicated, and what you want to do depends entirely on your workflow and how you relate to the parent project. Cherry-picking would work... so long as you're willing to make later merges of your feature branches complicated against the origin's master. Or you could rebase all of your branches so that feature2
applies cleanly against master
, or... about a dozen other methods. It really depends on your long term plan for these branches. In general, cut feature2
(and feature3
and so on) off master
if you can help it. It'll save you a lot of trouble down the line.
这篇关于如何将特征(在主题分支中)移植到另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!