假设我开始在明确的master
分支上工作 - no changes to commit
。做一些本地更改,但要意识到这种修改应该在一个单独branch
的而不是master
.
有没有办法将这些更改移动到将新分支branch
和重述master
分支分离为状态no changes to commit
?
编辑
遵循git 分支的公认答案 - 如何使当前 master 成为分支,然后将 master 恢复到以前的版本?...按照这些步骤,我的主人仍然会有修改过的文件。参见最后一条评论 7。
我错过了什么吗?
$ git branch # 1. starting on master
# On branch master
nothing to commit, working directory clean
# On branch master # 2.modifying a file
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash # 3. stashing changes
Saved working directory and index state WIP on master: 393bfad initial commit
HEAD is now at 393bfad initial commit
$ git status
# On branch master
nothing to commit, working directory clean
$ git checkout -b experiment # 4. creating new branch experiment
Switched to a new branch 'experiment'
$ git stash pop # 5. pop staged changes in exper.
# On branch experiment
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (16b6871d43f367edd03f59558eca4163cd1a2b2f)
$ git checkout master #6. going back to master
M test.txt
Switched to branch 'master'
git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test.txt #7. in master test.txt is still modified !!!