Skip to content

Instantly share code, notes, and snippets.

@r1chardj0n3s
Last active July 26, 2021 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r1chardj0n3s/7f2e94959fb533bd42dd35b94b8d590d to your computer and use it in GitHub Desktop.
Save r1chardj0n3s/7f2e94959fb533bd42dd35b94b8d590d to your computer and use it in GitHub Desktop.

HOW TO REVERT A BIT OF A PREVIOUS COMMIT

First revert the full commit (puts it in index) but don't commit, where -n is short for --no-commit:

git revert -n <sha1 to reverse>

Then interactively remove ("destage") the reverted GOOD changes from the index, where -p is short for --patch:

git reset -p

Then commit reverse diff of the bad changes:

git commit -m "Partially revert <sha1>..."

Finally the reverted GOOD changes (which have been unstaged by the reset command) are still in the working tree. They need to be cleaned up. If no other uncommitted changes are left in the working tree, this can be done by:

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