Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between `--squash` and `--no-ff --no-commit`?

Which one should one use to hide microcommits?

Is the only difference between git merge --squash and git merge --no-ff --no-commit the denial of the other parents?

like image 549
Tobias Kienzler Avatar asked Aug 16 '12 08:08

Tobias Kienzler


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.

What is the difference between squash and rebase?

Merge squash merges a tree (a sequence of commits) into a single commit. That is, it squashes all changes made in n commits into a single commit. Rebasing is re-basing, that is, choosing a new base (parent commit) for a tree.

What is squash and commit?

What does it mean to squash commits in Git? Squashing is a way to rewrite your commit history; this action helps to clean up and simplify your commit history before sharing your work with team members. Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit.

What does no commit mean?

Definition of noncommitment 1 : lack of commitment or a failure or refusal to commit to someone or something … doesn't excuse random instances of noncommitment in a long-term relationship.—


1 Answers

The differences

These options exists for separate purposes. Your repository ends up differently.

Let's suppose that your repository is like this after you are done developing on the topic branch:

enter image description here


--squash

If you checkout master and then git merge --squash topic; git commit -m topic, you get this:

enter image description here


--no-ff --no-commit

Instead, if you do git merge --no-ff --no-commit; git commit -m topic, you get this:

enter image description here

Hiding micro-commits

If you really want to hide (I mean delete from your repository) your micro-commits, use --squash. Because, as you can see in the above images, you are not really hiding your micro-commits if you do not squash. Moreover, you do not usually push your topic branches to the world. Topic branches are for topic to get mature.

If you want your history to have all your micro-commits, but leave them in another line of development (the green line in the above images), use --no-ff --no-commit. But please remember that a) this is not a branch, and b) does not really mean anything in Git because it is just another parent of your commit.

Please refer to Git Branching - What a Branch Is if you really want to understand.

like image 58
Yasushi Shoji Avatar answered Sep 29 '22 10:09

Yasushi Shoji