Git – How to “un-revert” a reverted Git commit

gitrevertundo

Given a change that has been committed using commit, and then reverted using revert, what is the best way to then undo that revert?

Ideally, this should be done with a new commit, so as to not re-write history.

Best Answer

git cherry-pick <original commit sha>
Will make a copy of the original commit, essentially re-applying the commit

Reverting the revert will do the same thing, with a messier commit message:
git revert <commit sha of the revert>

Either of these ways will allow you to git push without overwriting history, because it creates a new commit after the revert.
When typing the commit sha, you typically only need the first 5 or 6 characters:
git cherry-pick 6bfabc