gitgit-dangling

Git can't find dangling tree origin


I was running a difference checker between my current files and a backup of the files on my external drive, and I found some differences between a git repo and it's backup. The only differences were some extra files under .git/objects on the left side and two blank .git/objects/info and .git/objects/pack folders on the right. I did a quick git show and git log on both sides, which gave identical outputs.

Then I did a git fsck --no-reflogs, and found one extra dangling commit on the left side. Iteratively git ls-treeing my way down that extra commit gave me a bunch of trees and blobs that accounted for all but one of the extra files on the left side.

Using git cat-file -t <sha1> on that one last file told me it was a tree. However, I have used git ls-tree on every commit and still found no reference to this mysterious tree object. So where exactly did this file come from? I'm 99.99% sure it doesn't matter, just curious :P


Solution

  • meh, rookie mistake. Turns out, the extra dangling commit was pointing directly to the missing tree. I thought that doing git ls-tree <sha1> on a commit object would give the tree it was pointing to, but it actually gives the children of the tree it's pointing to. Using git cat-file -p <sha1>, which finds object contents, gave me the info I needed.

    So it seems like all files in .git/objects are either commits or dangling commits. I found this to be a great concise guide to how git objects work.