Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

revert

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.

like image 783
William Jones Avatar asked Mar 08 '10 04:03

William Jones


1 Answers

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.

like image 177
Greg Hewgill Avatar answered Oct 13 '22 00:10

Greg Hewgill