If there are uncommitted changes that will be overwritten by git checkout
the command will complain and abort. In that case git commit
or git stash
is necessary.
If there are uncommitted changes that will not be overwritten by git checkout
the command succeeds and the changes spilled into the new branch. If you don't want to see these changes in the new branch use git commit
or git stash
before git checkout
.
Unlike other commands (like git pull
and git rebase
) git checkout
doesn't have option --autostash
because it's meaningless: in most cases you don't want to automatically do git stash pop
when switching to a new branch.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…