无法切换回当前分支之前的分支

Not able to switch back to branch which is ahead of current branch

我在一个分支 "test" 工作并接受了拉动,现在我根据原点进行了更新。

git checkout develop

我结帐到 origin/develop 后面的分支 "develop",我复制了一些代码更改。现在我运行:

 git status

当我在分支 "test" 工作时,我得到了很多未跟踪的文件和未暂存的文件。现在我只想结帐回测试分支并推送我的更改。 我的改动很小,所以我可以还原并重做它们。 但是如何切换分支因为我得到错误:

error: The following untracked working tree files would be overwritten by checkout:

All untsaged and untracked files

Please move or remove them before you switch branches.

Aborting

需要帮助以便我可以返回测试分支并重做我的更改。

在这种情况下,stash 是你最好的朋友 - https://git-scm.com/docs/git-stash

这里有一个你如何解决它的例子,我已经从你检查开发的步骤走了

git checkout develop
git stash 
git checkout test
git stash pop
git add .
git commit -m 'YOUR MESSAGE'
git checkout develop

这应该适合你!