2

When I have to fix merge conflict, I would like to ask git to give me the $REMOTE, $BASE and $LOCAL files (because the option keepTemporaries does not seem to work, see this thread). Is there any command to do this?

Thanks!

Community
  • 1
  • 1
janou195
  • 1,175
  • 2
  • 10
  • 25

1 Answers1

2

From git help gitrevisions:

    :<n>:<path>, e.g. :0:README, :README
        A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the
        index at the given path. A missing stage number (and the colon that follows it) names a stage 0 entry. During a
        merge, stage 1 is the common ancestor, stage 2 is the target branch_s version (typically the current branch), and
        stage 3 is the version from the branch which is being merged.

So, if you are in the middle of git checkout mybranch; git merge otherbranch, and you have a conflict on conflict.txt, then, git show :2:conflict.txt will show the version of the file from mybranch (your "$LOCAL"), git show :3:conflict.txt will show the version from otherbranch (your "$REMOTE"), and git show :1:conflict.txt will show the version from the commit identified by git merge-base mybranch otherbranch (your "$BASE").

For files that are not in conflict, use git show :0:cleanfile.txt or just git show cleanfile.txt.

twalberg
  • 59,951
  • 11
  • 89
  • 84