Reset local repository branch to be just like remote repository HEAD

后端 未结 21 1887
挽巷
挽巷 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 02:53

    If you had a problem as me, that you have already committed some changes, but now, for any reason you want to get rid of it, the quickest way is to use git reset like this:

    git reset --hard HEAD~2
    

    I had 2 not needed commits, hence the number 2. You can change it to your own number of commits to reset.

    So answering your question - if you're 5 commits ahead of remote repository HEAD, you should run this command:

    git reset --hard HEAD~5
    

    Notice that you will lose the changes you've made, so be careful!

提交回复
热议问题