7

Assuming you have this:

     master: o--o--o
development:        `o--o--o

I want to merge the changes back as one commit (avoiding all the junk commits along the way):

git checkout master
git merge --squash development

But then the github network page shows this:

     master: o--o--o---------o
development:        `o--o--o

What are you supposed to do so it shows what you would expect, ie:

     master: o--o--o---------o
development:        `o--o--o’
Jay
  • 19,649
  • 38
  • 121
  • 184
  • You get the last graph by using `git merge --no-ff`. But note that the "junk commits" are still there. – Slaven Rezic Sep 27 '13 at 05:32
  • It is also worth noting that a "squash merge" is not a true merge (as your history shows you); it is indeed more of a "squash rebase". You'll probably get what you actually want, by squashing `development` first (**rewriting history**) and then normally merging the result into master. – Nevik Rehnel Sep 27 '13 at 05:39

1 Answers1

12

For the last graph, you can use the following command:

git merge --no-ff
git branch -d development

master: o--o--o---------o
               `o--o--o’

You tell git to create a merge commit, even if the merged branch is fast forward, i.e the last commit of master is a direct ancestor of the merged branch.

Note that the "junk commits" will no be deleted, but unless you have a really good reason, you should keep your history the way it is. Squashing commits makes it hard to browse your history.

If you feel your development branch history is full of crap, you can also rewrite it before merging, using an interactive rebase.

git checkout developement
git rebase -i master

You will be able to pick, edit, reorder, squash, or discard commits and rewrite your branch history. Once this is done, use a classic merge (with or without --no-ff, as you prefer).

Thibault J
  • 4,336
  • 33
  • 44