Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git merge --squash so that github "network" diagram shows the merge

Tags:

git

merge

github

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’
like image 211
Jay Avatar asked Sep 27 '13 05:09

Jay


People also ask

How do I merge squash with GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under "Pull Requests", select Allow squash merging. This allows contributors to merge a pull request by squashing all commits into a single commit.

How does squash and merge work GitHub?

When you select the Squash and merge option on a pull request on GitHub.com, the pull request's commits are squashed into a single commit. Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch.

What is the difference between squash and merge and merge?

A squash merge is a merge option in Git that will produce a merge commit with only one parent. The files are merged exactly as they would be in a normal merge, but the commit metadata is changed to show only one of the parent commits.

Can you squash a merge?

Squashing can be chosen as an option while merging in Git by adding --squash to your merge command.


1 Answers

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).

like image 189
Thibault J Avatar answered Sep 26 '22 02:09

Thibault J