git command for making one branch like another

前端 未结 9 1336
半阙折子戏
半阙折子戏 2020-11-22 11:36

I\'m trying to take a branch with changes and bring it back to be identical to the upstream it diverged from. The changes are both local and have been pushed to github, so n

9条回答
  •  佛祖请我去吃肉
    2020-11-22 12:03

    Use git reset BACKWARDS!

    You can make a branch look like any other commit with git reset, but you have to do it in a round-about way.

    To make a branch on commit look like a commit , you can do

    git reset --hard 
    

    in order to make the contents of the working tree.

    Then do

    git reset --mixed  
    

    to change the branch back to the original commit but leaving working tree in the state.

    Then you can add and commit the changes, in order to make your branch exactly match the contents of the commit.

    It's counter-intuitive that to move from the state to the you need to do a git reset from to . However with the option --mixed the working tree is left at and the branch pointer set to , so that when the changes are committed the branch looks how we want.

    Warning

    Don't lose track of your commits, e.g. forget what is when doing git reset --hard .

提交回复
热议问题