Skip to content

Instantly share code, notes, and snippets.

@UmairJibran
Last active October 27, 2022 11:08
Show Gist options
  • Select an option

  • Save UmairJibran/353d2e9ff4484af6948b53630ec7e274 to your computer and use it in GitHub Desktop.

Select an option

Save UmairJibran/353d2e9ff4484af6948b53630ec7e274 to your computer and use it in GitHub Desktop.
Rollback accidentally made (and pushed) commits
git checkout -b new-branch # new-branch or branch name where you actually wanted to make commit
git checkout master # master or any branch where you have accidentally made commit
git reset --hard HEAD~1 # replace 1 with number of commits you want to go back
git push --force # forces the remote to accept the <local> HEAD as new <remote> HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment