In Visual Studio, I can easily take the current (or incoming) branch’s changes while resolving merge conflicts. This is like merging with –ours (or –theirs) merge strategy for a single file. Could someone please tell me how I would do this on the command line 🙂
I have tried git checkout --ours -- $filename
. That exits with code 0, but when I run git status
, the file still shows as "both added". I am baffled at why this does not work.
2
Answers
It turns out that I had to run git checkout, as done in the question:
git checkout --ours -- $filename
.THEN, I had to run git add to get rid of the "both added" marking and finish resolving the conflicts in that file:
git add $filename
I can put them together like so:
git checkout --ours -- $filename && git add $filename
You can also try in one command
git restore --ours
, which replacesgit checkout
(since Git 2.23 Q3 2019):That would restore and add the file to the index.