Skip to content

Instantly share code, notes, and snippets.

@carltondickson
Created March 12, 2015 11:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save carltondickson/28a90ccfed2f6b697aba to your computer and use it in GitHub Desktop.
Save carltondickson/28a90ccfed2f6b697aba to your computer and use it in GitHub Desktop.
Undo commit and push to the wrong branch
# Credit to http://www.iarp.ca/hobby/computing/36-git-committed-and-pushed-to-the-incorrect-branch
# Ensure you're in the branch that you commited to by accident.
git checkout master
# Reset the branch back one commit.
git reset --soft HEAD^
# Stash the changes
git stash
# Checkout the branch it should be in
git checkout develop
# Apply the stash
git stash apply
# Commit the changes just as you did before, you will need to rewrite the message.
git commit.........
# Push the changes to our develop branch
git push origin develop
# Checkout the original branch
git checkout master
# Force push the commit deletion to the original branch.
git push --force origin master
@kutemeikito
Copy link

NICE JOB MAN,

@muchezz
Copy link

muchezz commented Aug 27, 2020

Thank you! This really saved me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment