How to undo a git pull?

前端 未结 6 795
灰色年华
灰色年华 2020-11-30 16:14

I would like to undo my git pull on account of unwanted commits on the remote origin, but I don\'t know to which revision I have to reset back to.

How can I just go

6条回答
  •  独厮守ぢ
    2020-11-30 16:37

    From https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undoamergeorpullinsideadirtyworkingtree

    Undo a merge or pull inside a dirty working tree

    $ 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.

    See also https://stackoverflow.com/a/30345382/621690

提交回复
热议问题