将更改的文件移到另一个分支进行签入
这经常发生在我身上:我写了一些代码,检查我的更改,然后意识到我不在适当的分支中来检查那些更改.但是,如果不恢复更改,我将无法切换到另一个分支.有没有办法将更改移动到另一个要在其中检查的分支?
This often happens to me: I write some code, go to check in my changes, and then realize I'm not in the proper branch to check in those changes. However I can't switch to another branch without my changes reverting. Is there a way to move changes to another branch to be checked in there?
git stash
是你的朋友.
如果尚未提交,只需运行git stash
.这样可以节省您的所有更改.
If you have not made the commit yet, just run git stash
. This will save away all of your changes.
切换到要在其上进行更改的分支,然后运行git stash pop
.
Switch to the branch you want the changes on and run git stash pop
.
git stash有很多用途.这当然是更有用的原因之一.
There are lots of uses for git stash. This is certainly one of the more useful reasons.
一个例子:
# work on some code
git stash
git checkout correct-branch
git stash pop