-2

I've gotten into some state with Git, and now I can't sync with Master.

The idea below is to abandon any changes I have locally for conflicts and use what's in Master. Unfortunately, Git won't allow me to do that. I've tried deleting the files and following Git's instructions to git rm XXX on the offending files. It even fails after a git reset --hard HEAD.

enter image description here

How do I force Git to take the remote's copy of files?

jww
  • 97,681
  • 90
  • 411
  • 885
  • what's the actual error - line endings? show `git diff`, and also: no screenshots of text please. Your main work flow problem seems to be relying on `git pull` instead of `git fetch; git xxxx` – AD7six Jun 15 '15 at 07:42
  • @AD7six - the error message is *"Merge conflict in test.cpp"*. I thought `git pull` gets the stuff from Master. See [Equivalent of “svn checkout” for git?](http://stackoverflow.com/q/18900774/608639) on Stack Overflow. – jww Jun 15 '15 at 08:01
  • The error message is in the screenshot - it's not what I asked for. In the case here `git pull` is a combination of `git fetch` and`git merge origin/master`. In your current circumstances it's a problem you're trying to do both fetch+merge in one step. – AD7six Jun 15 '15 at 08:03
  • @AD7six - The question at hand is *"Force git to take remote's version of a file?"*. Please ignore the screen shot. Focus on forcing Git to take whatever is in Master. – jww Jun 15 '15 at 08:08
  • 1
    You don't seem to want any help =). Good luck. – AD7six Jun 15 '15 at 08:08
  • I'm voting to close as a possible duplicate of [Force Git to overwrite local files on pull](http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull). I'm not sure how close a duplicate it is because many of the answers provided did not work for me (like `git reset --hard HEAD`). I deleted the local folder and re-checked out because it was easiest than continuing to try things to see what worked. – jww Jun 15 '15 at 12:39

3 Answers3

4
git fetch --all
git reset --hard origin/master

original link: How do I force "git pull" to overwrite local files?

Community
  • 1
  • 1
tning
  • 1,231
  • 10
  • 22
3

Many git commands no longer work as usual when you are in the middle of a merge conflict.

You can still use git checkout BRANCHNAME FILES..., and this is the only time you can use git checkout --theirs FILES... and git checkout --ours FILES...

Though if you're not aware of it, you might consider the benefits of (interactive) rebasing.

o11c
  • 15,265
  • 4
  • 50
  • 75
  • *"Though if you're not aware of it, you might consider the benefits..."* - Yeah, I'm not aware of much when it comes to Git. Git uses the wrong document model (there is one set of sources and it's the project's set), and it really complicates the simplest of tasks (*q.v.*). For example, `rm test.cpp && svn update` would have worked perfectly with subversion. Instead, I waste time searching and then have to ask on Stack Overflow. – jww Jun 15 '15 at 07:57
  • 1
    @jww the fact that SVN doesn't support basic project management features is not really a feature. – o11c Jun 15 '15 at 07:59
  • My bad... I should have qualified that with "Git uses the wrong document model ***for this project***". Don't fix what ain't broke... – jww Jun 15 '15 at 08:07
1

First thing you want to do is get out of the merge. You can do this with git merge --abort. Then you can do the reset to origin/master if you wish, but if you do, you will lose all of your commits since your last push. If instead you want to merge, resolving all conflicts by favoring what is on the server, do git merge -Xtheirs. This is the safest thing for you to do, as then you will have all of your changes in your history in case you need to refer back to them.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • Thanks David. I'll have to wait until my next round of troubles to test it. I ended up deleting the folder and re-checking out the repo. Its really sad Git makes this stuff so difficult that its easier to delete and start over. – jww Jun 15 '15 at 12:38