Check out specific commit

We can check out specific commit by using the following command.

git checkout <commit hash>

The commit hash is a 40 characters length of alphanumeric. We don’t necessarily need to write the all 40 characters. Just include the first few characters to allow git to identify that commit. For example: git checkout 123456 would be enough most of the time to identify a unique commit.

When you checkout certain commit. You’ll notice two things:

  1. The git checkout command prints a large paragraph of text. It is to warn you that you have checked out a branch without any pointers. That means that is a detached branch without any branch name. We usually checkout and work on branch instead of directly referring to commit hash.
  2. The files in the working directory changes to the state of that commit. Don’t worry, our commits are safe and we can checkout our latest code by doing git checkout master.

Read the “branch” and “git flow” section for more about using branches.