44

I just want to pull. I have changes to disregard, my Gemfile and Gemlock files and I'd be happy to just overwrite them and just pull. I tried stashing my changes away, this didn't work out for me. What do I do?

git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
~/projects/sms/apps2/apps2_admin(apps2)$ git stash save "saved"
Gemfile.lock: needs merge
Gemfile.lock: needs merge
Gemfile.lock: unmerged (4ea16799dba7bfe1db28adecf36dee1af5195c1a)
Gemfile.lock: unmerged (e77439c9f86d1d0eda7ae0787e3e158f90959e68)
Gemfile.lock: unmerged (d690d3860db1aa8e46c1bb2f4de3e52a297b5c26)
fatal: git-write-tree: error building trees
Cannot save the current index state
~/projects/sms/apps2/apps2_admin(apps2)$ git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
Flimm
  • 136,138
  • 45
  • 251
  • 267
JZ.
  • 21,147
  • 32
  • 115
  • 192
  • related: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull – rwilliams Nov 08 '11 at 00:50
  • 1
    for a full answer visit here http://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files – Harsukh Makwana Jul 25 '16 at 13:26
  • 1
    Possible duplicate of [Why does git say "Pull is not possible because you have unmerged files"?](http://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files) – Anshul Goyal Feb 02 '17 at 10:34

4 Answers4

83
git fetch origin
git reset --hard origin/master
git pull

Explanation:

  • Fetch will download everything from another repository, in this case, the one marked as "origin".
  • Reset will discard changes and revert to the mentioned branch, "master" in repository "origin".
  • Pull will just get everything from a remote repository and integrate.

See documentation at http://git-scm.com/docs.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
  • What does this do exactly? – Chemist Jan 12 '15 at 19:38
  • 2
    Fetch will download everything from another repository, in this case, the one marked as "origin". Reset will discard changes and revert to the mentioned branch, "master" in repository "origin". Pull will just get everything from a remote repository and integrate. See documentation at http://git-scm.com/docs/. – Ricardo Peres Jan 12 '15 at 22:21
44

You can use git checkout <file> to check out the committed version of the file (thus discarding your changes), or git reset --hard HEAD to throw away any uncommitted changes for all files.

Amber
  • 507,862
  • 82
  • 626
  • 550
2

I've tried both these and still get failure due to conflicts. At the end of my patience, I cloned master in another location, copied everything into the other branch and committed it. which let me continue. The "-X theirs" option should have done this for me, but it did not.

git merge -s recursive -X theirs master

error: 'merge' is not possible because you have unmerged files. hint: Fix them up in the work tree, hint: and then use 'git add/rm ' as hint: appropriate to mark resolution and make a commit, hint: or use 'git commit -a'. fatal: Exiting because of an unresolved conflict.

Community
  • 1
  • 1
max
  • 9,708
  • 15
  • 89
  • 144
1

I've had the same error and I solve it with: git merge -s recursive -X theirs origin/master

chacham15
  • 13,719
  • 26
  • 104
  • 207