git stash
is your friend.
If you have not made the commit yet, just run git stash
. This will save away all of your changes.
Switch to the branch you want the changes on and run git stash pop
.
There are lots of uses for git stash. This is certainly one of the more useful reasons.
An example:
# work on some code
git stash
git checkout correct-branch
git stash pop
Update: No need to use stash
command. uncommitted changes do not belong to any branch so just use git checkout -b <new-branch>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…