Home > Software design >  What is the Git CLI equivalent of "Keep Current" in Visual Studio Git Changes window?
What is the Git CLI equivalent of "Keep Current" in Visual Studio Git Changes window?

Time:12-09

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.

CodePudding user response:

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

CodePudding user response:

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.

  • Related