Git checkout a branchless commit

Viewed 1854

I've cloned a GitHub repository onto my local machine. I'd like the state of my local repository to reflect its state at a specific commit, so my instinct is to git checkout <commit>. However, doing so results in an error:

fatal: reference is not a tree: 7aa823a959e1f50c0dab9e01c1940235eccc04cc

Viewing the commit on GitHub yields the following warning:

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

What are my options? If it helps, the GitHub repository is the Linux kernel source tree and the commit in question is 7aa823a959e1f50c0dab9e01c1940235eccc04cc.

1 Answers

Apparently, being able to view a commit on the GitHub web interface doesn't necessarily mean the commit exists in the repository (hence the warning). I was able to confirm that my repository didn't contain the commit object in question using git cat-file -t <commit>.

Thus, I was able to solve my problem by searching GitHub for a suitable fork that contained the commit I needed.

Thanks to torek and ElpieKay for their help in the comments.

Related