John Little
John Little

Reputation: 12343

git merge question: how to accept your version of a file?

OK, I made a big mistake. I pushed a feature branch, and it was merged to main via PR. Then I made additional fixes to the feature branch, and committed that and tried to make a PR. It said there were merge conflicts. Im conflicting with myself.

So I did the following:

  1. git checkout main
  2. git pull // get the latest version of main
  3. git checkout myfeaturebranch
  4. git merge main // this generages conflits.

My file now has an incomprehensible set of === and >>> listed. I cant easily see which bits I should delete, and which bits I should keep.

What I really want to do is just keep the latest version on my branch, as its the newer version of whats in main.

I tried to do this via eclipse merge tool, but this tool only offers to copy from right (server) to left (my version), and of course I want the other way round. The merge tool has no option to take the left version.

So I have two options:

  1. try to edit the file, but this is likely to result in broken code.
  2. clone the repo in a different dir, checkout my branch, copy the contents of the file into the current cloned version, save it, commit it.

Presumably there are other options (ideally not dangerous or arcane?)

Upvotes: 0

Views: 499

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21938

How to handle it via CLI :

git checkout --ours -- path/to/file

where
--ours asks for the receiving branch's version of the file (doc)
-- means "end of options, everything past this is pathspecs" (doc)

Then just add your file and commit the merge when you're done with other conflicts.

Upvotes: 1

Related Questions