Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining merges into a single merge

Tags:

git

Suppose I have a mainline branch and a feature branch. I have merged the mainline branch into the feature branch many times, but I have only had a few, very minor merge conflicts. I want to clean up the history so that there is only a single merge at the end. What is the best method for doing this?

like image 922
Casebash Avatar asked Oct 23 '22 14:10

Casebash


2 Answers

Have you looked into git rebase?

git co -b temp_feature feature
git rebase master

This should ignore the merges, but you will have to re-resolve the conflicts. It also creates temp_feature branch for easier go back but same could be achieved with reflog.

(Wrong answer below: this will create single commit, not a single merge :-/)

I think the simplest is to do following:

git co master
git merge --squash feature

This will create single commit from whole feature branch. If you do not want to keep the feature branch do:

git branch -D feature
like image 185
Martian Avatar answered Oct 27 '22 11:10

Martian


Sounds like you want to cherrypick the non-merge commits for the feature branch into clean-feature branch, then finally merge clean-feature branch with the latest master (whatever that is). You can use rebase to speedup part of that cherrypicking, which unfortunately I don't know of a good way to do in a jiffy, since this is not something I do very often. It would help if you have a gui that allows you to select multiple commits to be cherrypicked at once.

Edit: This would be a more concrete solution: How to cherry pick a range of commits and merge into another branch

like image 43
prusswan Avatar answered Oct 27 '22 10:10

prusswan