Review the result of git-merge before the actual merge

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.

  • Revert to pre-git v1.7.8 git submodule behavior with submodule filesystem locations
  • Upstream pulls with the GitHub desktop client
  • How does Git's typical workflow compare to Mercurial's?
  • How can you set it up so that your project automatically updates on your production server when you make changes to a github repository?
  • How to setup and clone a remote git repo on Windows?
  • KDiff3 under cygwin git will not invoke
  • Does git provide a command or a feature that would accomplishes this?

  • Custom post-receive file using GitLab
  • Git branching: master vs. origin/master vs. remotes/origin/master
  • git.exe has been suddenly gone on Windows
  • Pushing to a remote branch (failed to update ref)
  • How to delete a commit on a git remote?
  • Pod install is staying on “Setting up CocoaPods Master repo”
  • 3 Solutions collect form web for “Review the result of git-merge before the actual merge”

    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 back up 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.

    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.

    Git Baby is a git and github fan, let's start git clone.