Is there a way to review the result of a merge between two branches before actually merging them ?
When attempting to merge branch A to branch B, I usually checkout a temporary branch from B, merge it with branch A, then I'd create a diff patch, or just checkout to that temporary branch and check whether everything is working fine before merging A to B.
Does git provide a command or a feature that would accomplishes this?
Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. Note that all of the commands presented below merge into the current branch.
Merging. When you run git merge , your HEAD branch will generate a new commit, preserving the ancestry of each commit history.
After a git merge stops due to conflicts you can conclude the merge by running git merge --continue (see "HOW TO RESOLVE CONFLICTS" section below). Commits, usually other branch heads, to merge into our branch.
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.
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.
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