12

i forked a project from github, and the origin point to my own github repo, remote point to its original repo, since i want to get update from remote,

i use git pull remote branch_name, then my local repo is in conflict mode, now i want to cancel the effect of git pull, so i use git stash, but was surprised to find i failed to do this? what's wrong?

the detailed info is as follows:

[mirror@home weechat]$ git status
# On branch master
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      CMakeLists.txt
#       both modified:      ChangeLog
#       both modified:      NEWS
#       both modified:      configure.in
#       both modified:      po/cs.po
#       both modified:      po/de.po
#       both modified:      po/es.po
#       both modified:      po/fr.po
#       both modified:      po/hu.po
#       both modified:      po/ru.po
#       both modified:      po/weechat.pot
#       deleted by us:      src/irc/irc-server.c
#       both modified:      weechat.spec
#
no changes added to commit (use "git add" and/or "git commit -a")
[mirror@home weechat]$ git stash
CMakeLists.txt: needs merge
ChangeLog: needs merge
NEWS: needs merge
configure.in: needs merge
po/cs.po: needs merge
po/de.po: needs merge
po/es.po: needs merge
po/fr.po: needs merge
po/hu.po: needs merge
po/ru.po: needs merge
po/weechat.pot: needs merge
src/irc/irc-server.c: needs merge
weechat.spec: needs merge
CMakeLists.txt: needs merge
ChangeLog: needs merge
NEWS: needs merge
configure.in: needs merge
po/cs.po: needs merge
po/de.po: needs merge
po/es.po: needs merge
po/fr.po: needs merge
po/hu.po: needs merge
po/ru.po: needs merge
po/weechat.pot: needs merge
src/irc/irc-server.c: needs merge
weechat.spec: needs merge
CMakeLists.txt: unmerged (118d776a202cfc6688290e96fca20ac4f8631f5e)
CMakeLists.txt: unmerged (d05c9a9711a965dcad0aefa03b79ae7a4f5cb8fb)
CMakeLists.txt: unmerged (dd2b14cb188e1927e098705d77e922ad530e232b)
ChangeLog: unmerged (764711936b54aa75812828e1ab15e1632aa3eb9d)
ChangeLog: unmerged (e00d4bf654c3d199e24bf4910b066f1659fea4b6)
ChangeLog: unmerged (dbec2315ffc1f15feede248abe3ed85beaa82ed7)
NEWS: unmerged (457d5443548e6130b50e42a9c87a6f2e8ba4c596)
NEWS: unmerged (706cee4b8853013f20129ccb2fa9057b7500fceb)
NEWS: unmerged (33afffbac62399faa32e2560a9accd95dd9a050e)
configure.in: unmerged (8e1058e5e00a5e671459cee8300420b0488560d9)
...
fatal: git-write-tree: error building trees
Cannot save the current index state

so how to cannel the effect of git pull? should i delete repo, and download it again?

hugemeow
  • 7,777
  • 13
  • 50
  • 63

2 Answers2

11

Run git merge --abort.

You are in the middle of a merge, so stashing is definitely not something you should do (you would lose the history information associated with the merge).

user1338062
  • 11,939
  • 3
  • 73
  • 67
  • why git stash will lose history? which kind of history it would lose? i think pull can only happen when all changes are commited:) – hugemeow Aug 27 '12 at 18:26
  • 1
    Running `git reset; git stash save` will allow you to save the state of the working directory, but it looses all conflict information, since it resets the index. – jpaugh Mar 01 '19 at 17:06
7

git stash is to save the changes for future use, not for canceling a conflicted state, that's why it doesn't work.

Instead use git reset ORIG_HEAD (see How to undo a git pull?)

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • stash is used to abandon modification, why it is used to save changes? – hugemeow Aug 27 '12 at 18:21
  • 2
    No, stash is used to save modifications made on a working copy and discard them, in the perspective of restoring them later with `git stash pop`. Abandoning modifications is done by `git reset` – CharlesB Aug 27 '12 at 23:04
  • in what situation i should use git stash? if i use git reset here, the merge history will be lost, but if i use git stash, it not works, why? since i cannot save some code which is in confliction, right? – hugemeow Aug 28 '12 at 00:36