Every so often one will run into a situation where someone made some mistakes and you really just need to roll back in the git history.

One may be in distress, maybe do a haphazard search something something “reset my branch to previous commit” and click the first stack overflow link. Another may ask the AI overlords for advice. Both cases often end with the bad advice of the “force push”. sigh

git reset <commit sha>
git push -f origin main

This unassuming sequence of commands could get you to your desired state, but at a cost. The version history will be rewritten. One could experience data loss or make distributed contributions troublesome with divergent histories. If we learned anything from time travel tropes: don’t mess with history!

Fret not, for there is an easier way. git provides us with a revert. A revert will function similarly to reset, however it will create a new commit with the appropriate delta between the HEAD and the desired point in history. Since a new commit is created history remains unaffected and allows one to restore to a previous point in your branch.

git revert <commit sha>
git push origin main

–daryl