You can do the following:
git checkout --detach
git reset --soft master
git checkout master
Explanation:
If you are on the debug
branch and would do git reset --soft master
you would leave your working tree and index untouched and move to the commit master
points to. The problem is, debug
will be reset to this commit too. So your commits on debug
are "lost" (well, not really, but they are not directly accessible anymore) and you are still on the debug
branch.
To prevent git reset
from moving debug
but still setting your HEAD
to the master
commit, you first do git checkout --detach
to point HEAD
directly to your current commit (see man git-checkout
, section "DETACHED HEAD"). Then you can do the reset without touching the debug
branch.
Now HEAD
is pointing directly to the commit master
points to, i.e. it is still detached. You can simply git checkout master
to attach to master
and are now ready to commit on the master
branch.
Note that git checkout
(by default and when no path is passed) only updates files that have been changed between the "source" and "target" commit and local modifications to the files in the working tree are kept. As both commits are the same in this case, no files in the working directory are touched.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…