Reputation: 339
I'd like to perform the following transformation in Git : To remove the 2 merge commits and replace them with individual commits from the 2 green and pink branchs (I want a linear history)
I've checked the similar questions on SO, and I thought that these commands would simply do the job, without any conflict, since Git would be smart enough to use the merge commits when rebasing :
git checkout master
git rebase c
# (I am allowed to force-push btw)
git push --force
But I get an (unexpected for me) conflict during rebase because of commit C .... :(
Is there any way of achieving this linear commit history w/o any conflict to be resolved ? Should I do it in two+ steps ?
NOTE1: There are actually many more commits between E and D, between c and a and between 1 and 2, so I'd like to avoid tedious manual cherry-picks.... :) (I've posted a simplified graph for the question)
NOTE2: It works fine when there is only one merge commits, following the 3rd tip in this SO answer. But here there are 2 merge commits as you can see in the pic.
Thanks in advance for your help ?
Upvotes: 0
Views: 87
Reputation: 18886
If you want all the individual commits, choose to fast-forward merge when you do
Because you've merged already, you should be able to re-merge the commits or cherry-pick 'em over (though this is almost-certainly worse and much less-obvious than leaving things as they are)
In your example, if there are any conflicting changes in the other branches merged after C
, you'll need to regenerate it into some C'
, which contains the merge conflict fix of the branch and C
Additionally, the history is linear, and assuming the unlabeled merge of the pink branch before D
is a squash merge on top of C
in your example, that merge actually contains both
You can show this by attempting to revert it How to revert a merge commit that's already pushed to remote branch?
What you probably want in the future is to periodically merge your main branch into your development branch
Upvotes: 1