I recreated this kind of conflict:
$ git merge b1
CONFLICT (add/add): Merge conflict in newfile
Auto-merging newfile
Automatic merge failed; fix conflicts and then commit the result.
and indeed, there's Git's attempt to merge the files in the work-tree:
$ cat newfile
<<<<<<< HEAD
different contents - add a file
||||||| merged common ancestors
=======
add a file
>>>>>>> b1
Your method will work fine. This one is not much shorter, and has potential glitches with end-of-line modifications depending on your Git vintage:
$ git show :2:newfile > other_file # extract --ours version, to new name
$ git checkout --theirs newfile
Updated 1 path from the index
$ git add newfile other_file
$ it status -s
M newfile
A other_file
As the (short) status
shows, the two files are now ready to be committed. Their contents are:
$ cat newfile
add a file
$ cat other_file
different contents - add a file
Note that git show
does not run smudge filters and does not do end-of-line conversions, at least in older versions of Git (Git has acquired the ability to do text conversions and maybe git show
does them by default now—I have not tested this).