How to undo a git pull?

前端 未结 6 812
灰色年华
灰色年华 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:48

    Or to make it more explicit than the other answer:

    git pull 
    

    whoops?

    git reset --keep HEAD@{1}
    

    Versions of git older than 1.7.1 do not have --keep. If you use such version, you could use --hard - but that is a dangerous operation because it loses any local changes.


    To the commenter

    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)

提交回复
热议问题