Git: Discard all changes on a diverged local branch

后端 未结 2 1320
无人共我
无人共我 2021-01-29 20:03

I have a local topic branch that\'s tracking a remote branch. For the sake of argument, say the commit histories look like this:

A--B--C--O1--O2--O3 (origin/phob         


        
相关标签:
2条回答
  • 2021-01-29 20:21

    Delete the branch, then re-create it:

    $ git branch -D phobos
    $ git checkout --track -b phobos origin/phobos
    
    0 讨论(0)
  • 2021-01-29 20:33
    git checkout phobos
    git reset --hard origin/phobos
    

    This tells Git to reset the head of phobos to the same commit as origin/phobos, and to update the working tree to match.

    0 讨论(0)
提交回复
热议问题