Using git, how do I go back to first commit then go through the history?

Solution 1:

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.

Solution 2:

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