How to undo a git pull?

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

    Even though the above solutions do work,This answer is for you in case you want to reverse the clock instead of undoing a git pull.I mean if you want to get your exact repo the way it was X Mins back then run the command

    git reset --hard branchName@{"X Minutes ago"}

    Note: before you actually go ahead and run this command please only try this command if you are sure about the time you want to go back to and heres about my situation.

    I was currently on a branch develop, I was supposed to checkout to a new branch and pull in another branch lets say Branch A but I accidentally ran git pull origin B before checking out.

    so to undo this change I tried this command

    git reset --hard develop@{"10 Minutes ago"}

    if you are on windows cmd and get error: unknown switch `e

    try adding quotes like this

    git reset --hard 'develop@{"10 Minutes ago"}'

提交回复
热议问题