On daily routine i use SmartGit
as client of choose. My team members however stick to git native, non commercial GUI. We discovered some differences in how our merge commits looks like.
Those are options that SmartGit
gives when requested to merge branch:
On below graph you can see my example SmartGit graph output, containing:
master
branchmerge commit
optionsimple commit
optionOne of branches (with_merge_branch
) is visualizing merge operation by joining branch with master via line. Second one (normal_commit_branch
) does not.
Question is, how to enforce both behaviors in native git commands? I.e. whats the difference between those two commits?
You should consider using squash if your team prefers a linear project history. This means that the history held by your main branch should not contain merges. A squash merge makes it possible to keep changes condensed to a single commit, supporting this strategy nicely.
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.
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.
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.
The difference between the two kinds of merge are only different in the commit history (as you showed the logs in graph).
Let's illustrate by graphs. Assume the commit history as below before merging:
A---B---C---D master \ E---F---G develop
The command used is git merge branchname
. It's the default way to merge two branches.
When you merge develop
branch into master
branch by Merge commit in SmartGit (git merge develop
), the commit history will be:
A---B---C---D---M master \ / E---F---G develop
It merges two branches with --squash
option, the command used is git merge branchname --squash
.
--squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).
When you merge develop
branch into master
branch by simple commit in SmartGit (git merge develop --squash
), it get the changes from develop
branch into master
branch as a new ordinary commit (as if a real merge happened), and the commit history will be:
A---B---C---D---M master \ E---F---G develop
merge commits
are just commit
but the difference is they have more than one parents. as you know commits may or may not have parent commit, in fact the merge commit
is the commit
that have more than one parent commit
.
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