skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. You can also try in one command git restore --ours, which replaces git checkout (since Git 2.23 Q3 2019):

    git restore -SW --ours -- $filename
    

    That would restore and add the file to the index.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search