Review the result of git-merge before the actual merge
I call this the "code review workflow" and do it all the time.
git merge --no-commit --no-ff branchname
Without the --no-ff
flag, if Git can do a fast-forward then it will do that. (As expected, as in the case of a fast forward, there's no merge commit to create.)
I have this alias setup in .gitconfig
for convenience:
rev = merge --no-ff --no-commit
So that I can simply do:
git rev branchname
The idea is that all features are developed in separate branches, and each feature is reviewed and merged by somebody other than the author. As other answers pointed out you can abort the merge with:
git reset --merge
and ask the author to make more changes.
To view the log with only the merge commits I use this other alias:
revlog = log --first-parent
This way the log becomes a timeline of the large steps: feature by feature rather than commit by commit.
As Marian Theisen suggested, you can do this to do the merge without committing
git merge --no-commit <branchname>
You can back out of that merge with
git reset --hard
Also, remember that it is always easy to change your mind and return to a previous state in Git. You can do a full merge, including commit, inspect the complete result and if you change your mind you can
git reset --hard HEAD^
to throw away the merge and be back at the commit before the merge.
In fact, at any point during the merge resolution, you can do
git reset --merge
To abort the merge and throw away just the merge changes.
Why take the trouble? Just do the merge, test it, and if you don't like it, then git reset --hard HEAD^
to move back to pre-merge state. Doing some temporary or half-way merge just increases your work whether you decide you want to keep the merge or not.