Merging two very divergent branches using git? -
i have master
branch , verydifferentbranch
these had same ancestor ... 300 commits ago. verydifferentbranch
feature complete i'd put under master branch
. doing rebase results in every single patch having lot of merge conflicts, point large project unto go through conflicts.
i have no idea except force pushing head of verydifferentbranch
master
branch. i'd losing history doing this, , that's not want do.
what other options?
it sounds history looks this:
...---o---a---o---...---o---o---b master \ o---o---...---o---c verydifferentbranch
you worried losing history if force push verydifferentbranch
master
. such operation throwing away after a
, b
.
you can preserve history merging it, or dropping tag @ abandoned branch tip , leaving unmerged.
use merge
a merge allow keep both sides of history:
...---o---a---o---...---o---o---b \ \ o---o---...---o---c---m master
the kind of merge determine content created commit m. normal merge (using recursive
merge strategy) sounds produce large number of conflicts in case. if need incorporate changes a..b
commits, there nothing else work through conflicts presented either merge or rebase. (in future have fewer problems if can merge or rebase more deal conflicts arise.) but, if want m
have same content c
(i.e. want ignore changes represented a..b
commits), can use ours
merge strategy.
git-merge(1) describes ours
merge strategy:
this resolves number of heads, resulting tree of merge of current branch head, ignoring changes other branches. meant used supersede old development history of side branches. note different -xours option recursive merge strategy.
you can produce m message of merge commit 'abandoned/foo-features'
this:
git tag -m 'describe reason abandonment here...' \ abandoned/foo-features master # tag abandoned branch tip git checkout verydifferentbranch # checkout dominant branch git branch -m verydifferentbranch master # replace master git merge -s ours abandoned/foo-features # merge other's history git tag -d abandoned/foo-features # optional: delete tag git push wherever master tag abandoned/foo-features # publish them
variations on these commands give different automatic commit messages m
(you can supply own git merge -m
or amend git commit --amend
afterwards).
the main point resulting master
have both pieces of history, none of changes original master
side (those changes still in history, not represented in tree referenced commit m
).
leave hanging
if acceptable “rewrite” master
(i.e. there no other work based on of commits a..b
, or users involved not mind work take recover rewrite), leave tag @ current tip of master
, replace master
verydifferentbranch
.
...---o---a---o---...---o---o---b (tag: abandoned/foo-features) \ o---o---...---o---c master
arrange so:
git tag -m 'describe reason abandonment here...' \ abandoned/foo-features master # tag abandoned branch tip git branch -m verydifferentbranch master # replace master git push wherever +master tag abandoned/foo-features # publish them
Comments
Post a Comment