0

I'm doing some test, and I created a local repos to version some files. I would like to restore all my files to their state at a previous commit.

Is it possible ? I know that git checkout file restore a file to the current commit state. However I'm not sure if git checkout * do the same for all file, and even more here I'm not sure if it's possible to restore from more than just the latest commit.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ryu415
  • 1
  • 1
  • 2

3 Answers3

0

You can use this command.

git log
git checkout <commit_hash>
BStar
  • 1
  • 1
0

If you have one previous commit and you have done some local changes without committing again, and you want to go back to the "checkpoint" (commit):

git reset --hard HEAD

You don't even need to know any commit hash, it will just bring you back to your HEAD, deleting everything that happened after.

buondevid
  • 347
  • 2
  • 7
0

I recommend checking out the answer posted here:Chris Lloyd's answer to: How can I reset or revert a file to a specific revision?

Here's a quick summary of his answer:

  1. Enter the command git log in your terminal to find a list of all your commits.
  2. Find the second to last commit's hash (here's an example: 72ba15b8de0c7689d0819136917f61e6f9715c2a)
  3. git diff <commit hash> <filename>
  4. git reset <commit hash> <filename>
  5. git checkout <commit hash>

You should now be inside your former commit files.