5

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.

2
  • 3
    "reference is not a tree" means you can't check it out. Use git cat-file -t 7aa823a959e1f50c0dab9e01c1940235eccc04cc to see if the object exists at all in your repository (it probably doesn't). GitHub uses some funky stuff behind Git's back to combine storage for forks, and this means that sometimes you can "see" a commit that isn't actually there, through their web interface. This appears to be such a case. If you can figure out which fork actually holds that commit, you could clone that fork. Commented Jan 15, 2021 at 0:00
  • 2
    Search All Github for this commit and there are 221 commit results, github.com/…. You could fetch it from any of these repositories whose branch/tag actually holds it. Commented Jan 15, 2021 at 2:32

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.