No need to stash.
(不需要藏匿。)
git checkout -b new_branch_name
does not touch your local changes.
(不会触及您当地的更改。)
It just creates the branch from the current HEAD and sets the HEAD there. (它只是从当前HEAD创建分支并在那里设置HEAD。)
So I guess that's what you want. (所以我想这就是你想要的。)
--- Edit to explain the result of checkout master ---
(---编辑解释结账大师的结果---)
Are you confused because checkout master
does not discard your changes?
(您是否感到困惑,因为checkout master
不会丢弃您的更改?)
Since the changes are only local, git does not want you to lose them too easily.
(由于更改只是本地的,因此git不希望您太容易丢失它们。)
Upon changing branch, git does not overwrite your local changes. (更改分支后,git不会覆盖您的本地更改。)
The result of your checkout master
is: (checkout master
的结果是:)
M testing
, which means that your working files are not clean.
(,这意味着您的工作文件不干净。)
git did change the HEAD, but did not overwrite your local files. (git确实改变了HEAD,但没有覆盖你的本地文件。)
That is why your last status still show your local changes, although you are on master
. (这就是为什么你的上一个状态仍然显示你的本地更改,虽然你是master
。)
If you really want to discard the local changes, you have to force the checkout with -f
.
(如果您确实要放弃本地更改,则必须使用-f
强制结帐。)
git checkout master -f
Since your changes were never committed, you'd lose them.
(由于您的更改从未提交过,因此您将失去它们。)
Try to get back to your branch, commit your changes, then checkout the master again.
(尝试返回到您的分支,提交更改,然后再次检出主服务器。)
git checkout new_branch
git commit -a -m"edited"
git checkout master
git status
You should get a M
message after the first checkout, but then not anymore after the checkout master
, and git status
should show no modified files.
(您应该在第一次结账后收到M
消息,但在checkout master
后不再显示,并且git status
应显示没有修改过的文件。)
--- Edit to clear up confusion about working directory (local files)---
(---编辑以清除工作目录(本地文件)的混乱---)
In answer to your first comment, local changes are just... well, local.
(在回答您的第一条评论时,本地变化只是......好吧,本地。)
Git does not save them automatically, you must tell it to save them for later. (Git不会自动保存它们,您必须告诉它以便以后保存它们。)
If you make changes and do not explicitly commit or stash them, git will not version them. (如果您进行更改并且未显式提交或存储它们,则git不会对它们进行版本控制。)
If you change HEAD ( checkout master
), the local changes are not overwritten since unsaved. (如果更改HEAD( checkout master
),则自未保存后不会覆盖本地更改。)