所以我有以下情况:
我在本地提交了一些工作,没有推送到远程存储库。我想将这个本地代码移动到另一个分支,因为如果我 pull ,将会有修改会破坏我在本地所做的所有工作。
这是旧分支上 git status
的输出:
On branch <branch_name>
Your branch is ahead of 'origin/<branch_name>' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
这是 git status
在新创建的分支上的输出:
On branch <branch_name>
nothing to commit, working directory clean
最佳答案
如果只是一次提交,你可以简单地做
git reset HEAD~1
git stash
git checkout anotherbranch
git stash pop
如果你想把它放在一个全新的分支中,另一种方法是
git branch newbranch
git reset --hard HEAD~1
关于git - 如何将未推送的提交代码移动到另一个分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45216144/