Home > Software engineering >  File associated with a dangling blob
File associated with a dangling blob

Time:08-22

I ran git fsck and obtained the following:

Checking object directories: 100% (256/256), done.
Checking objects: 100% (2338/2338), done.
dangling blob b16084cfd9ca4429688cf5cf7a1948d4307f31f7

From previous questions on dangling blobs (See here, for instance) it is clear that this is not something to worry about and that it is a normal part of garbage collection process. However, I would like to find out what exactly this blob corresponds to.

Can one get, for instance, some data of which date this blob was made? What is the directory structure/file name that this blob corresponds to?

One of the answers here suggested to try git show b16084cfd9ca4429688cf5cf7a1948d4307f31f7 but this does not produce any text/human readable output. Perhaps this blob was referring to some nontext file/folder.

CodePudding user response:

It is a blob (a file content), but it's "dangling" status means it is not referenced by anything else, and that you won't find its name in git.

From your comment to @AntonioPetricca's answer : it is not a text file.

One way to get more indication is to store it on disk and use a utility such as file :

git show b16084cf... > myblob
file myblob

If you know what kind of files you have in your directory (images ? zip or gzip files ? office document ? other binary files ?) you may guess what kind of file it is, and try to open it with an appropriate program (an image editor, an archive reader, office ...)


A dangling blob shouldn't be packed with other objects, so you can get an indication of when it was created (e.g : git added) by looking at the creation date of :

ls -l .git/objects/b1/6084cf...

CodePudding user response:

Please try with git cat-file -p b16084cfd9ca4429688cf5cf7a1948d4307f31f7.

CodePudding user response:

A blob is an object of the content of a file. From the blob hash, we cannot tell which file has the content.

First we list all commit objects,

git cat-file --batch-all-objects --batch-check | grep commit

We would get something like

1ff20d2c13f216e96cf623238242661105a97b67 commit 230
26179ca322862f4f5f74e229d6d22dff739e588b commit 183

Each line has the hash of a commit object, the object type commit and its size in byte. To search a commit object for the blob b16084cfd9ca4429688cf5cf7a1948d4307f31f7, we can use

git ls-tree -r 1ff20d2c13f216e96cf623238242661105a97b67 | grep b16084cfd9ca4429688cf5cf7a1948d4307f31f7

If the blob is found, it would print something like

100644 blob b16084cfd9ca4429688cf5cf7a1948d4307f31f7    path/to/foo.bar

So we can know the commit(s) that have the blob and its corresponding path or paths in the repository. To combine the commands,

git cat-file --batch-all-objects --batch-check | grep commit | while read osha1 otype osize;do
    result=$(git ls-tree -r $osha1 | grep -e b16084cfd9ca4429688cf5cf7a1948d4307f31f7)
    if [[ "$result" != "" ]];then
        echo commit: $osha1, $result
    fi
done
  •  Tags:  
  • git
  • Related