Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: get ours/theirs file content during merge

Tags:

git

I know I can get the ours/theirs state by invoking

git checkout --ours/--theirs -- path/to/my/file.txt

but this will overwrite the file in my working tree. How to get the file content of the ours/theirs file state during merge without overwriting the working tree?

like image 394
Thomas S. Avatar asked Jun 26 '17 07:06

Thomas S.


1 Answers

Hidden in the docs :

git show :1:file/path   # base
git show :2:file/path   # ours
git show :3:file/path   # theirs

When a merge conflict is triggered because of a merge action, HEAD still points to the original commit, and MERGE_HEAD to the commit trying to be merged in, so :

git show HEAD:file/path        # ours
git show MERGE_HEAD:file/path  # theirs

will also work, and perhaps be more explicit to the user.

like image 109
LeGEC Avatar answered Sep 18 '22 18:09

LeGEC