9

So I was just trying to upload my code to git, I don't know what I did but somehow i'm in a bit of pickle.

Because there are so many conflicts in almost all of my files.

I don't want to resolve each conflict manually by going through each file because there are hundreds of files and there are multiple conflicts in each file.

So how do I tell git to accept all current changes but not the incoming changes or vice versa? Thanks

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Danz Tim
  • 180
  • 1
  • 3
  • 10
  • If you undo the merge (`git reset `), and you're ready to push... `git push -f` will forcefully push your changes. This will overwrite history though (and probably has some bad consequences if hundreds of files have changed), so be careful. – byxor Oct 14 '19 at 13:59
  • You have to deal with the conflicts. And you have to do it now (you cannot deal with them during a later commit). Unless, of course, you did something blatantly wrong. Ignoring conflicts and saying "I'm right, they are wrong" without looking does not get you anywhere. – j6t Oct 14 '19 at 14:06

4 Answers4

10
git checkout --theirs .
git add .

or

git checkout --ours .
git add .
Luca Borrione
  • 16,324
  • 8
  • 52
  • 66
8
git checkout --ours [filename]
git add [filename]

https://dev.to/willamesoares/git-ours-or-theirs-part1-agh

To initiate the merge with this intent, see this post.

isherwood
  • 58,414
  • 16
  • 114
  • 157
5

If you are using Visual Studio Code, then you could:

  1. Select all the files having conflicts under Git sidebar icon

  2. Right click and then choose Accept All Current or Accept All Incoming.

  3. Save all the automatically changed files.

  4. Stage Changes.

enter image description here

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Frank Wang
  • 51
  • 1
  • 3
3

So how do I tell git to accept all current changes but not the incoming changes or vice versa? Thanks

From the docs: https://git-scm.com/docs/git-checkout


You have to use merge strategies,

git checkout --ours / --theirs

When checking out paths from the index, check out stage (ours) or (theirs) for unmerged paths.


Short post:

http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html


Note by @j69

Be warned: checkout --ours and checkout --theirs erases all of the not-chosen edits in the file, even the ones outside the conflicts.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167