Reset local repository branch to be just like remote repository HEAD

后端 未结 21 1620
挽巷
挽巷 2020-11-22 02:19

How do I reset my local branch to be just like the branch on the remote repository?

I did:

git reset --hard HEAD

But when I run a <

21条回答
  •  旧时难觅i
    2020-11-22 03:07

    git reset --hard HEAD actually only resets to the last committed state. In this case HEAD refers to the HEAD of your branch.

    If you have several commits, this won't work..

    What you probably want to do, is reset to the head of origin or whatever you remote repository is called. I'd probably just do something like

    git reset --hard origin/HEAD
    

    Be careful though. Hard resets cannot easily be undone. It is better to do as Dan suggests, and branch off a copy of your changes before resetting.

提交回复
热议问题