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’
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.
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.
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.
Squashing can be chosen as an option while merging in Git by adding --squash to your merge command.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With