Git: How to revert everything exactly to the state of a prior commit?

git, revert

Solution

It sounds like you want to put your current work on a branch:

git branch saved_work
git reset --hard previouscommit

Now, your `saved_work` branch contains everything after `previouscommit`, and `master` is rewound to `previouscommit`.

Problem

If there have been commits and many changes since an earlier commit, is there a simple way to revert everything to the exact state of that earlier commit? If so, is it possible to easily switch back to the current state if I should so desire as well? I've realized that this old commit is actually the correct one, and want to maintain all changes since then only for reference, but all future work will be based on this old commit.

Original source