Git双向合并 [英] Git bi-directional merging
问题描述
我想知道处理这种git场景的最佳方法:
I'm wanting to know the best approach for dealing with this git scenario:
Git仓库a:CoreProduct
Git repo a: CoreProduct
Git回购b:SpecificCustomerProduct,它是从a
Git repo b: SpecificCustomerProduct which was forked from a
到目前为止,我们对a和b进行了不同的更改,仅将a合并为b.到目前为止一切都很好-特定产品正在从我们的CorePoduct中获得功能
Up until now, we have been making different changes to both a and b, and only merging a down to b. All good so far - the specific product is gaining features from our CorePoduct
现在,我们已经在b中完成了 some 次提交,我们希望返回到a中(并且a中有一些新内容也需要照常降为b) )
Now, we have ended up with some commits in b, that we would like to get back up into a (and there is new stuff in a that also needs to come down to b as usual)
问题: 将这些特定的提交从b提升到a的最佳方法是什么,目的是使我们从a到b的更规则的合并尽可能不费力地向前推进?
Question: What is the best way to get these specific commits from b up to a, with the intent of keeping our more regular merges from a to b as painless as possible moving forward?
问题: 如果我们是从头开始做的,那你会怎么做?
Question: If we were doing this from scratch, how would you do it?
我当时想将b的提交内容挑选到b上的一个临时分支中,然后拉请求"该分支到a,但是担心会影响将来从a到b的合并.
I was thinking of cherrypicking commits from b into a temp branch on b and then 'pull request' that branch up to a, but am concerned about that affecting future merges from a to b..
推荐答案
假设您的仓库具有以下结构:
Suppose your repo has such a structure:
... --- A1(branch_A)
\
\
... ------ B1(branch_B)
我的建议是:
(1)以防万一,请先用git branch bak_A branch_A
和git branch bak_B branch_B
备份分支.
(1) Just in case, backup your branches first by git branch bak_A branch_A
and git branch bak_B branch_B
.
(2)git checkout branch_A
,进行修改(通过选择樱桃或合并,然后进行任何操作),然后提交,您将获得一个像这样的A2(B1和A2之间的边缘可能不存在,并且不存在)没关系):
(2) git checkout branch_A
, do the modifications (by cherry-picking or by merging, whatever you want) then commit, you will get a A2 like this (the edge between B1 and A2 may not exists, and it doesn't matter):
... --- A1 --- A2(branch_A)
\ /
\ /
... ------ B1(branch_B)
(3)git checkout branch_B
,然后是git commit-tree branch_B^{tree} -p branch_B -p branch_A -m "<commit messages>" | xargs -I {} git merge {}
,您将获得:
(3) git checkout branch_B
, then git commit-tree branch_B^{tree} -p branch_B -p branch_A -m "<commit messages>" | xargs -I {} git merge {}
, you will get:
... --- A1 --- A2(branch_A)
\ / \
\ / \
... ------ B1 --- B2(branch_B)
其中B1和B2具有相同的内容.
in which B1 and B2 have the same content.
(4)现在,您可以像以前一样继续开发.如果出现任何问题,可以通过git branch -f branch_A bak_A
和git branch -f branch_B bak_B
恢复分支.
(4) Now you can continue your development as before. If anything goes wrong, you can restore your branches by git branch -f branch_A bak_A
and git branch -f branch_B bak_B
.
这篇关于Git双向合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!