Question

I have a simple scenario:

2 branches: master and myownb:

myownb is ahead of the master branch with 3 commits:

What I need is to "merge" these 2 branches, but not in the classic mode.

I would like all these 3 commits from myownb to be pushed as only one commit to the master branch (and preferably with a different commit message).

Or to create a patch of all the differences between these 2 branches, to be later applied to my master branch, and commit as I wish.

Was it helpful?

Solution

What I would do in this instance is perform an interactive rebase. This will allow you to do everything you mentioned (squash to one commit, and provide a different commit message).

From myownb you would write git rebase -i HEAD~3 because you're 3 commits ahead of when you branched off of master. In the dialog box that appears you should see your 3 commits in order, something like:

interactive rebase screen

You have to pick one so that the others have a basis with which to be squashed, for the second and third commits change pick to s or squash. Once you've done that save and quit the file. Once you've done that the commit message window will pop up.

enter image description here

In this window is where you'll be able to write your single commit message. Delete all of the generic messages that it gives and write your single commit message. Once you've done that, save and quit the file.

Back in your terminal you should be all set. Running a git log you'll see that all you have now are the commits leading up to master, and then a single commit with those three commits you had previously.

To finish, git checkout master and then git merge myownb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top