且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否需要在`git checkout`之前运行`git stash push`?

更新时间:2022-03-14 22:31:35

如果存在未提交的更改,这些更改将被git checkout覆盖,该命令将抱怨并中止.在这种情况下,必须使用git commitgit stash.

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.

如果存在未提交的更改,且不会被git checkout覆盖,则命令将成功执行,并且更改将溢出到新分支中.如果不想在新分支中看到这些更改,请在git checkout之前使用git commitgit stash.

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.

与其他命令(例如git pullgit rebase)不同,git checkout没有选项--autostash,因为它没有意义:在大多数情况下,当您切换到新命令时,您不想自动执行git stash pop分支.

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.