I cloned a project from Github and now I wish to revert it to the first commit, how would I do this? Also, once I am back to the first commit, how do I go up to the second commit, and then from the second to the third and so on.
3 Answers
You can check out any revision by giving its SHA1 id:
git checkout <SHA1>
A helper script called git-walk
has been made for this. Even if you won't use the explicit script, look at the (very simple) code to see what is done.
Adapted from the answer to What is the opposite of git diff HEAD^
?:
First, to make your life easier later on, you can setup a local alias to find the initial commit and the child of a particular commit (Note: this is not always possible because of the way a DAG works)
git config --local alias.first-sha "!git rev-list --all | tail -n 1"
git config --local alias.child-sha "!git rev-list HEAD..master | tail -n 1"
Then you can checkout the initial commit and step through the code by checking out each child-sha:
git checkout $(git first-sha)
git checkout $(git child-sha)
If you're new to git, I suggest reading an article I wrote about Stepping Through Commits which details more about each of the commands being used
for all files, try
git show HEAD
for a particular file, try
git log -p filename
git log
would help here.