Last active
March 17, 2016 19:23
-
-
Save jacopotarantino/df7ebd8b506b055a5599 to your computer and use it in GitHub Desktop.
A walkthrough for undoing changes in your current branch but backing them up to another branch for future use.
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
# WARNING: seriously please be careful with this if you don't know what you're doing. | |
# Reverting, resetting, and force-pushing are all actions that can make you lose work. | |
# If you lose that work you will be unhappy and your coworkers will hate you. | |
# You've been warned. | |
# okay, so if you’re on the branch that has the work | |
# (let’s assume master) the flow looks like this: | |
git checkout master | |
# you should already be here but all the same... | |
git checkout -b backup/my-feature | |
git log | |
# make sure that you're definitely on the new branch and it definitely has your work in it. | |
git push | |
# this should just work assuming you have your git config set to 'simple' | |
# make sure that your new branch made it to github. | |
git checkout master | |
# now that we have a backup go back to modify the original. | |
git reset --hard head~5 | |
# or however many commits. maybe do it 1 at a time just to be safe. | |
git log | |
# double check that you've reverted to exactly the commit you meant to | |
git push --force | |
# Push the stable changes out to origin | |
# WARNING: THIS IS DANGEROUS AND CAN IRREVOCABLE DELETE WORK ON THE REMOTE | |
# the --force flag is necessary since your head will be behind the remote head. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment