Switching branches without touching the working tree?

前端 未结 5 527
無奈伤痛
無奈伤痛 2020-12-07 18:56

I am currently on a debug branch, and would like to switch to the master branch, without modifying the working tree (leave it the way it is in the debug branch), so I can co

5条回答
  •  渐次进展
    2020-12-07 19:18

    This answer uses low-level "plumbing" commands. Be careful. If you prefer "porcelain" commands, go with this answer which produces the same results.

    You can reset your head to point at master without changing the index or working tree with:

    git symbolic-ref HEAD refs/heads/master
    

    You should probably reset the index so that you can selectively apply your working tree changes, otherwise you may end up committing all the differences between master and the debug branch, which is probably a bad thing.

    git reset
    

    Once you've made the commit that you want to make you can return to your debug branch with:

    git symbolic-ref HEAD refs/heads/debug-branch
    git reset
    

提交回复
热议问题