How do I git checkout one commit prior to a specific commit

git

Solution

Here you go:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^

Notice the `^` at the end. That means one revision behind.

For example this would be 5 revisions behind:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^^^^^

... equivalent to:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d~5

Btw, when you do this, you'll be in a detached HEAD state. The output explains this, which is very interesting and worth reading:

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b new_branch_name

Problem

After going through github issues, I've found a commit that might be responsible for breaking code and I want to confirm this suspicion by doing something like: `git checkout --one-prior f1962b3cc771184a471e1350fa280d80d5fdd09d`

Original source