Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Git merge --squash and --no-commit

Tags:

git

merge

squash

As the title says, I am not really clear about the differences between a git merge --squash and a git merge --no-commit.

As far as I understand the help page for git merge, both commands would leave me in an updated working-tree, where it is still possible to edit and then to do a final commit (or multiple commits).

Could someone clarify the differences of those 2 options? When would I use one instead of the other?

like image 758
quaylar Avatar asked Mar 07 '12 10:03

quaylar


People also ask

What is the difference between squash merge and merge commit?

Squash merging is a merge option that allows you to condense the Git history of topic branches when you complete a pull request. Instead of each commit on the topic branch being added to the history of the default branch, a squash merge adds all the file changes to a single new commit on the default branch.

Is it better to squash and merge?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.

Should I squash commits or not?

Before you start, keep in mind that you should squash your commits BEFORE you ever push your changes to a remote repository. If you rewrite your history once others have made changes to it, you're asking for trouble… or conflicts.

Can I merge without commit?

With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.


1 Answers

git merge --no-commit 

This is just like a normal merge but doesn't create a merge-commit. This commit will be a merge commit: when you look at the history, your commit will appear as a normal merge.

git merge --squash 

This will merge the changes into your working tree without creating a merge commit. When you commit the merged changes, it will look like a new "normal" commit on your branch: without a merge commit in the history. It's almost like you did a cherry-pick on all the merged changes.

like image 128
ralphtheninja Avatar answered Oct 08 '22 05:10

ralphtheninja