Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
Duplicate over at Stack Overflow: Git, Revert to a commit by SHA hash? –  Bobby Apr 12 '12 at 8:05
@Bobby: Well, in a way it's a dupe, but the specific application in this case of walking through every revision chronologically is a bit different. Not much, though. –  Daniel Andersson Apr 12 '12 at 9:00
@DanielAndersson: Not really, at least not in my opinion. "Checking out a specific revision" is not that much different from "Checking out a specific revision and after that checking out the next revision". Though, knowing about git log would help here. –  Bobby Apr 12 '12 at 9:07
why would you want to do that?, can you explain what are you trying to do, instead what you want to do? –  KurzedMetal Apr 12 '12 at 14:37

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer

for all files, try

git show HEAD 

for a particular file, try

git log -p filename
share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.