Skip to content

Instantly share code, notes, and snippets.

@xenogew
Created June 20, 2018 07:07
Show Gist options
  • Save xenogew/48116948c914b697ef5e2b4d9c52b576 to your computer and use it in GitHub Desktop.
Save xenogew/48116948c914b697ef5e2b4d9c52b576 to your computer and use it in GitHub Desktop.
How to remove last commit on remote

History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

git push origin +dd61ab32^:master

Where git interprets x^ as the parent of x and + as a forced non-fastforward push. If you have the master branch checked out locally, you can also do it in two simpler steps: First reset the branch to the parent of the current commit, then force-push it to the remote.

Some part from: https://gist.github.com/gunjanpatel/18f9e4d1eb609597c50c2118e416e6a6 thanks for knowledge you published

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