Reputation: 14417
I have
G---H---I---J Develop
/
A---B---C---D---E---F Master
I want to rebase Develop with master, so:
G---H---I---J Develop
/
A---B---C---D---E---F Master
So if I do git checkout develop & git rebase master
It will do the rebase, however, at each commit where it finds a merge conflict it will stop.
I'm happy just to take everything from develop and overwrite with that. There have been massive changes with develop but each commit builds and passes all tests, so I can assume if I just overwrite everything in master it should be fine.
So how do I say something like git rebase master --choose develop side
Upvotes: 1
Views: 4532
Reputation: 45659
I think there's some ambiguity in the statement
I'm happy just to take everything from develop and overwrite with that
(or at least in how people are readying it).
Do you mean "where there's a conflict I'm happy taking what's in develop
"? That's what junkangli's answer (git rebase -X theirs master
) is about. And while that is one way to understand what you asked, it is unlikely that the result will be code that builds and runs.
Another way to read this would be that you want to take everything - conflicting or not - from develop
- i.e. discard any changes that were made in E
and F
because the changes from develop
were so profound that E
and F
just aren't worth the trouble any more.
In that case, you have a few options, depending on what you want in the final history.
My recommendation would be:
# make sure you're on master
git checkout master
# revert the commits that are going to be clobbered
git revert -n HEAD^ HEAD
git commit
# merge the branch
git merge develop
This preserves E
and F
in history, along with a commit that clearly says "I'm consciously undoing these changes". You'd end up with
G - H -- I -- J Develop
/ \
A - B - C - D - E - F - ~EF - M Master
Since you were wanting to rebase, you might not like that end state. Another option is to do the revert as above, then rebase develop to master; since the content (TREE
) at ~EF
matches the tree at D
, this should work without conflict and give you
A - B - C - D - E - F - ~EF - G` - H` - I` - J` Develop , Master
Assuming develop
had previously been pushed, after doing this you would have to "force push" it (push -f
); and this will create an "upstream rebase" situation for all other users of the repo; see the git rebase
docs for more information including the steps for them to recover, and understand that if you don't coordinate with everyone affected, someone taking the wrong steps to recover could undo what you've done.
For completeness, the actual simplest approach (but not one I recommend, especially if others share the repo) would be to just reset
the master
ref to J
.
git checkout master
git reset --hard develop
This would rewrite the history of the master
branch, so to push master
you'd have to use the -f
option (force push); and this again creates what is effectively an "upstream rebase" situation. It also means that E
and F
are scrubbed from history altogether (unless you put a new tag or branch on them).
Upvotes: 0