Git error on checkout: "fatal: reference is not a tree"
Asked Answered
J

3

9

It all started when I decided to figure out why the project I'm working on weighs so much. I've run the following script:

git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

And figured out which commits have the heaviest files. Next, I would like to see who is the author of those commits and when trying to run something like:

git show --stat COMMIT_HASH

I get a pile of gobbledygook and when I try rolling back to the commit, I get the above mentioned error.

So my question is: how do I find the author of the commit?

Jackofalltrades answered 16/1, 2019 at 20:42 Comment(0)
B
5

Your git show command should work. Either the hash is not valid or the commit object has been corrupted in some way.

Updated: Your script returns object hashes, so probably the reference for that object is invalid somehow.

You wouldn't be able to get the author reference from there anyhow.

This might help, it will list all the commits where the object whose hash you provide has been modified:

git log --find-object=OBJECT_HASH

Bothy answered 16/1, 2019 at 21:2 Comment(4)
well I took the hash corresponding to the commit with the heaviest file, the hash was yielded by the bash script. But in that case , is there a simple way to remove the object?Jackofalltrades
but before doing that I would actually like to find out the author of the commit.Jackofalltrades
I have to update my answer. I ran your command and noticed that it returns object hashes, not commit hashes.Bothy
I've added a tip that might be useful.Bothy
G
13

In my case, I run git fetch before checkout specific revision and it work.

Glassware answered 26/9, 2019 at 2:57 Comment(0)
B
5

Your git show command should work. Either the hash is not valid or the commit object has been corrupted in some way.

Updated: Your script returns object hashes, so probably the reference for that object is invalid somehow.

You wouldn't be able to get the author reference from there anyhow.

This might help, it will list all the commits where the object whose hash you provide has been modified:

git log --find-object=OBJECT_HASH

Bothy answered 16/1, 2019 at 21:2 Comment(4)
well I took the hash corresponding to the commit with the heaviest file, the hash was yielded by the bash script. But in that case , is there a simple way to remove the object?Jackofalltrades
but before doing that I would actually like to find out the author of the commit.Jackofalltrades
I have to update my answer. I ran your command and noticed that it returns object hashes, not commit hashes.Bothy
I've added a tip that might be useful.Bothy
B
0

Although different from the actual question of OP. You will get the same fatal: reference is not a tree error when you execute, for instance, a git checkout <hash> on the wrong repository for which this hash doesn't exist. I encountered it when I was trying to checkout to a specific hash, while I didn't notice that I was in a submodule directory instead of the main one I was trying to checkout for. Simply returning to the correct directory, and therefore, correct repository and the checkout worked (obviously).

Bessiebessy answered 19/7 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.