10

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.

4
  • 1
    Duplicate over at Stack Overflow: Git, Revert to a commit by SHA hash?
    – Bobby
    Apr 12, 2012 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. Apr 12, 2012 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, 2012 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? Apr 12, 2012 at 14:37

3 Answers 3

8

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.

4

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

-1

for all files, try

git show HEAD 

for a particular file, try

git log -p filename
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .