上下文:我正在为主人添加简单功能。几分钟后,我意识到它不是那么简单,而且应该更好地工作到一个新的分支。Git:从主机上未分期/未分配更改创建分支
这种情况一直发生在我身上,我不知道如何切换到另一个分支,并采取所有这些无法完成的更改,使主分支保持干净。我认为git stash && git stash branch new_branch
会简单地实现这一点,但是这是我得到:
~/test $ git status
# On branch master
nothing to commit (working directory clean)
~/test $ echo "hello!" > testing
~/test $ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
~/test $ git stash
Saved working directory and index state WIP on master: 4402b8c testing
HEAD is now at 4402b8c testing
~/test $ git status
# On branch master
nothing to commit (working directory clean)
~/test $ git stash branch new_branch
Switched to a new branch 'new_branch'
# On branch new_branch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/[email protected]{0} (db1b9a3391a82d86c9fdd26dab095ba9b820e35b)
~/test $ git s
# On branch new_branch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
~/test $ git checkout master
M testing
Switched to branch 'master'
~/test $ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
你知道是否有实现这个的方法吗?
虽然有一个简单的解决方案,以你的问题,你能在你得到的结果是什么,从你想有什么不同规定? – Gauthier 2010-04-02 22:41:37
通过执行上述操作或底部的答案,未完成的更改同时在主分支和新分支上。我只希望他们在新的分支,所以我可以签出主人并在另一件事上工作,而不会在 – knoopx 2010-04-02 22:56:18
附近浮动这些更改。请参阅我编辑的答案。如果您想签出干净的主文件,则需要在新分支上提交本地更改。本地更改只是当前HEAD和磁盘上的文件之间的差异。本地文件上的这些更改没有版本化,如果您想稍后检索它们,则需要告诉git将它们保存在某处。 – Gauthier 2010-04-02 23:07:07