Skip to content

Instantly share code, notes, and snippets.

@moonraker22
Created May 20, 2023 16:41
Show Gist options
  • Select an option

  • Save moonraker22/229b6299f3629018e31cb8b5031dc165 to your computer and use it in GitHub Desktop.

Select an option

Save moonraker22/229b6299f3629018e31cb8b5031dc165 to your computer and use it in GitHub Desktop.
revert commit safely
# Create a backup of master branch
git branch backup_master
# Point master to '56e05fce' and
# make working directory the same with '56e05fce'
git reset --hard 56e05fce
# Point master back to 'backup_master' and
# leave working directory the same with '56e05fce'.
git reset --soft backup_master
# Now working directory is the same '56e05fce' and
# master points to the original revision. Then we create a commit.
git commit -a -m "Revert to 56e05fce"
# Delete unused branch
git branch -d backup_master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment