I'm curious about this behavior and maybe its just because I've come from using SVN and bazaar mostly. (I'm learning git to interface with the excellent github.)
It seems counter intuitive to me and as if it would be better for
git merge [branch] --no-commit
to be the default to encourage people to make sure the merge went the way they wanted it to before committing.
By default, Git does not create an extra merge commit when merging a commit that is a descendant of the current commit. Instead, the tip of the current branch is fast-forwarded.
This usually happens when we're collaborating on a branch with other people, and we've made changes on our local version of a branch, and someone else (or the other you, if you use git to sync between multiple dev platforms) has made changes to the remote version of a branch in the meantime.
Merging your branch into master is the most common way to do this. Git creates a new commit (M) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.
The goal set by Linus Torvalds when creating Git was to make all the merges that could be automatically solved... FAST. See his 2007 Google Tech Talk: Linus Torvalds on Git (transcript)
I.e. hundreds of merges in less than a few seconds.
So a "--no-commit
" by default would pretty much defeat that purpose.
With
--no-commit
perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committing.
Extract from Linus's talk (video):
The only thing that matters is how fast can you merge.
In git, you can merge... I merge 22,000 files several times a day, and I get unhappy if a merge takes more than 5 seconds, and all of those 5 seconds is just downloading all the diffs, well not the diffs but its the deltas between two trees, the merge itself takes less than half a second.
And I do not have to think about it.
[...]That's the kind of performance that actually changes how you work.
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