“This is the real secret of life -- to be completely engaged with what you are doing in the here and now. And instead of calling it work, realize it is play.” ― Alan Watts

Git - revert to a previous commit

October 12, 2019

Ever needed to scrap some recent changes in your repo and just go back to a previous commit? Yeah me too, sometimes we need to undo the past and luckily with GIT we can go back in time.

For this you can use the git revert command, with the --no-commit flag.

Usually the (git revert) command automatically creates some commits with commit log messages stating which commits were reverted. This (--no-commit) flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.

git revert --no-commit 0766c053..HEAD
git commit

Obviously you would replace the commit hash with your own.