4

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

CodeWizard
  • 110,388
  • 20
  • 126
  • 153
Danz Tim
  • 129
  • 2
  • 9
  • 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

3 Answers3

4
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
  • 52,576
  • 15
  • 105
  • 143
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
  • 110,388
  • 20
  • 126
  • 153
3
git checkout --theirs .
git add .

or

git checkout --ours .
git add .
Luca Borrione
  • 15,747
  • 7
  • 49
  • 64