I have edits to my working tree which I would like to continue working on in a branch. Will git checkout -b new_branch
wipe out my current changes to the working tree? If so, how do I create a new branch and switch to it without reverting my working tree?
我编辑了我的工作树,我想继续在分支机构工作。 git checkout -b new_branch会消除我对工作树的当前更改吗?如果是这样,我如何创建一个新分支并切换到它而不还原我的工作树?
2 个解决方案
#1
Just do git checkout -b new_branch
. It will create the new branch with the changes in your working tree untouched.
只需要git checkout -b new_branch。它将创建新分支,而工作树中的更改不会受到影响。
#2
If in the future you need to see whether Git would destroy something you haven’t committed yet (which it generally will never do), use git stash
to stow away your changes. It will not save files that Git does not know about but Git will also refuse to overwrite unknown files in case of checkouts and similar operations.
如果将来你需要看看Git是否会破坏你尚未提交的东西(它通常永远不会做),使用git stash来存放你的更改。它不会保存Git不知道的文件,但Git也会在结帐和类似操作时拒绝覆盖未知文件。
#1
Just do git checkout -b new_branch
. It will create the new branch with the changes in your working tree untouched.
只需要git checkout -b new_branch。它将创建新分支,而工作树中的更改不会受到影响。
#2
If in the future you need to see whether Git would destroy something you haven’t committed yet (which it generally will never do), use git stash
to stow away your changes. It will not save files that Git does not know about but Git will also refuse to overwrite unknown files in case of checkouts and similar operations.
如果将来你需要看看Git是否会破坏你尚未提交的东西(它通常永远不会做),使用git stash来存放你的更改。它不会保存Git不知道的文件,但Git也会在结帐和类似操作时拒绝覆盖未知文件。