Switching branches without touching the working tree?

前端 未结 5 514
無奈伤痛
無奈伤痛 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:32

    Here is a raw workflow

     git stash
     git checkout otherbranch
     git stash apply
     git reset
     git add # interactively? just add the hunks/changes you want to commit
     git commit
    

    And to go back

     git reset --hard # watch it here! make sure you haven't added more changes that you wanted to keep
     git checkout debug
     git stash pop
    

    Alternatively, you might just commit the relevant changes 'here' and push / cherry-pick onto the master branch.

提交回复
热议问题