Created
October 10, 2011 06:42
-
-
Save mipearson/1274761 to your computer and use it in GitHub Desktop.
Oops! I committed this to the wrong branch in git!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Oops! I committed this to the wrong branch. | |
# Here's how to fix without needing to do a messy git revert. | |
# Assumptions: | |
# * you have no uncommitted changes | |
# * you haven't pushed or pulled yet | |
# * you haven't made any further commits | |
DEST = bar # branch you intended to commit to | |
SRC = foo # branch you actually committed to | |
git checkout $DEST # switch to the destination branch | |
git cherry-pick $SRC # copy the commit to the destination branch | |
git checkout $SRC # switch back to the source branch | |
git reset --hard HEAD^ # roll back the source branch one commit | |
# alternatively, you can use a git-merge instead of a | |
# git-cherry-pick if you know what you're doing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment