Home > front end >  Obtaining a flat list of all blobs in a .git/objects/ folder
Obtaining a flat list of all blobs in a .git/objects/ folder

Time:11-30

In the .git/objects/ folder there are many folders with files within such as ab/cde.... I understand that these are actually blobs abcde...

Is there a way to obtain a flat file listing of all blobs under .git/objects/ with no / being used a delimitor between ab and cde in the example above? For e.g.

abcde....
ab812....
74axs...

I tried

/.git/objects$ du -a .

This does list recursively all folders and files within the /objects/ folder but the blobs are not listed since the command lists the folder followed by the filename (as the OS recognizes them, as opposed to git). Furthermore, the du command does not provide a flat listing in a single column -- it provides the output in two columns with a numeric entry (disk usage) in the first column.

CodePudding user response:

If you are in the .git/objects/ folder

Try this.

find . -type f | sed -e 's/.git\/objects\///' | sed -e 's/\///'

sed -e requires the sed script, which means a find/replace pattern.

's/.git\/objects\///' finds .git/objects/ and replace it to '' which is nothing. therefore sed command remove the pattern.

\ in the pattern is an escape character.

After first sed command ends, the results will be (in linux.)

61/87c3f3d6c61c1a6ea475afb64265b83e73ec26

To remove / which refers a directory sign,

sed -e 's/\///'

If you are in the directory which contains .git

find .git/objects/ -type f | sed -e 's/.git\/objects\///' | sed -e 's/\///'

try this.

CodePudding user response:

I think you should start round here (git version 2.37.2):

git rev-list --all --objects --filter=object:type=blob

Doing it this way offers the advantage of not only checking the directory where the unpacked objects are but also the objects that are already packed (which are not in that directory anymore).

  • Related