如何撤消git pull?

How to undo a git pull?

我想撤销我的git拉取,因为远程源站上不需要的提交,但我不知道我必须重新设置到哪个版本。

我怎么能在Git拉上远程来源之前回到这个州呢?


或者比其他答案更明确:

1
git pull

哎呀?

1
git reset --keep HEAD@{1}

早于1.7.1的Git版本没有--keep。如果使用这种版本,可以使用--hard,但这是一个危险的操作,因为它会丢失任何本地更改。

致评论人

ORIG_HEAD is previous state of HEAD, set by commands that have possibly dangerous behavior, to be easy to revert them. It is less useful now that Git has reflog: HEAD@{1} is roughly equivalent to ORIG_HEAD (HEAD@{1} is always last value of HEAD, ORIG_HEAD is last value of HEAD before dangerous operation)


git reflog show应该显示头部的历史。你可以用它来找出你在江户前的位置。然后你可以用你的HEAD来承诺。


这对我很有用。

1
git reset --hard ORIG_HEAD

撤消合并或拉:

1
2
3
4
5
6
7
8
9
$ git pull                         (1)
Auto-merging nitfol
CONFLICT (content): Merge conflict in nitfol
Automatic merge failed; fix conflicts and then commit the result.
$ git reset --hard                 (2)
$ git pull . topic/branch          (3)
Updating from 41223... to 13134...
Fast-forward
$ git reset --hard ORIG_HEAD       (4)

检查这个:头部和orig_头部在git更多。


找到你想去的承诺书。您可以在Github中找到它,也可以在命令行中键入git loggit reflog show,然后执行此操作。埃多克斯1〔9〕


来自https://git scm.com/docs/git reset documentation/git-reset.txt-undoamergeorpullinsideadirtyworkstree

Undo a merge or pull inside a dirty working tree

1
2
3
4
5
6
$ git pull           (1)
Auto-merging nitfol
Merge made by recursive.
 nitfol               |   20 +++++----
 ...
$ git reset --merge ORIG_HEAD      (2)

Even if
you may have local modifications in your working tree, you can safely
say git pull when you know that the change in the other branch does
not overlap with them.

After inspecting the result of the merge, you may find that the change
in the other branch is unsatisfactory. Running git reset --hard ORIG_HEAD
will let you go back to where you were, but it will discard
your local changes, which you do not want. git reset --merge keeps
your local changes.

另请参阅https://stackoverflow.com/a/30345382/621690