Skip to content

Instantly share code, notes, and snippets.

@jaumef
Last active March 17, 2017 08:55
Show Gist options
  • Save jaumef/77ee11f3fd217a9647edd5ba8fcfffa7 to your computer and use it in GitHub Desktop.
Save jaumef/77ee11f3fd217a9647edd5ba8fcfffa7 to your computer and use it in GitHub Desktop.

UNDO COMMITS

BEFORE PUSH

Push backwards current HEAD, uncommitting last commit but keeping files

git reset HEAD^ 

Reset to a past HEAD, removing unpushed changes (hard) or keeping modified files (soft)

git reset HEAD --[hard|soft]

AFTER PUSH

If it's the last commit pushed, push backwards your HEAD and then push the head to ORIGIN

git reset HEAD^
git push origin +HEAD

# Recommended to push only specified branch HEADs:
git push origin +HEAD:<branch_name>

If lots of commits have been pushed there's no way to erase only one commit...

But you can revert the changes using:

git revert <commit_hash>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment