我们知道,如果有一天我们在错误分支上修改了代码。
这时候,我们想切换到正确分支,我们需要把修改的代码stash到缓冲区,切换完分支后,pop出来,然后在提交。
git stash
git checkout targetbranch
git stash pop
git add .
git commit -m xxx
但是如果我们在错误分支有新增的文件,会出现直接stash会出现错误
我们可以把新增的文件add到暂存区,然后在stash
git add 新增文件
git stash
git checkout targetbranch
git stash pop
新增文件这时是暂存状态,不过无所谓