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.

  • GIT — push everything to remote server, but with only with one log entry
  • deploying app on openshift - git and ssh key not working
  • Git log output messed up
  • Git: Editing a file in a bare repo using Git plumbing commands
  • Understanding Git for Visual Studio 2015: Revert
  • Git-p4 issues when trying to submit back to perforce
  • Does git provide a command or a feature that would accomplishes this?

  • pull instead of fetch - accidentally merged remote master into local branch
  • Definitively delete the tracking of .DS_Store files in GIT
  • Git repository icon
  • Git On Custom SSH Port
  • Is there a way to get git status to show 2 remotes
  • Unable to take snapshots or use git in XCode 4.6
  • 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.