上下文:我正在使用master添加一个简单的功能。几分钟后,我意识到这并不是那么简单,应该更好地在一个新分支中工作。
这种情况总是发生在我身上,我不知道如何切换到另一个分支并将所有这些未提交的更改与我一起离开主分支干净。我以为git stash && git stash branch new_branch
会简单地完成这一点,但这就是我得到的:
~/test $ git status# On branch masternothing 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 stashSaved working directory and index state WIP on master: 4402b8c testingHEAD is now at 4402b8c testing
~/test $ git status# On branch masternothing to commit (working directory clean)
~/test $ git stash branch new_branchSwitched 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/stash@{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 masterM testingSwitched 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")
你知道有没有什么办法可以做到这一点吗?