Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using --filter=blob:none when cloning doesn't seem to be having an effect; Have I misunderstood?

Tags:

git

I'm trying to maintain some old shell scripts and found this command to checkout a git repo

git clone --filter=blob:none <repo> <folder>

with a comment saying 'Do partial clone as we don't need all the git history'.

I'd not come across this before and did some googling and it seems --filter=blob:none should essentially mean no files are actually checked out and git will do it as needed.

However I have a repo that I have tried cloning with --filter=blob:none

git clone --filter=blob:none <my repo> <the folder>

Once this completes I go into <the folder> and everything seems to be there and I can open files.

if I change directory in to <the folder> I can run git log and see the commit history.

It seems to me that this is no different than just doing a git clone with no filter?

I did try a normal git clone and while there was some differences in the log output from git, the end folder it produced was the same.

So my question is - What exactly is --filter=blob:none doing, why don't I see a difference? (I've done this on both linux and windows)

Thanks

like image 250
Dave Avatar asked Oct 20 '25 00:10

Dave


1 Answers

The --filter=blob:none option is not supposed to change the contents of your working folder or workspace. In fact, that is just the nice feature of it! All files will be there. It will only make a difference on the amount of data that git will copy into the .git/objects folder. All objects that are blobs (i.e. pure file data) will only be downloaded on demand; and the objects you need for the HEAD commit, will all be available.

So to make the real comparison, clone the remote git repo, twice; once with the --filter=blob:none and once without, and then compare the size of the .git/objects folder with e.g. du -sh .git/objects of both clones.

If the remote contains a lot of commits or contains a lot of binary files, the difference should be substantial.

BTW, I saw references above stating that Git considers anything above a certain filesize as a 'blob', which is wrong. For Git, all files are 'blobs', i.e. size doesn't matter. A blob is essentially the file contents and the size; not the name or any other meta information, just the contents and the size.

A good presentation on the --filter=blob:none feature can be found here.

An extremely good introduction to Git, which I can highly recommend as it will provide you with more insight in what goes on, under the hood, can be found here. If you really want to become fluent in Git, this is essential information. It is very well described and is sprinkled with small command line samples to try.

like image 71
Steven Buytaert Avatar answered Oct 22 '25 06:10

Steven Buytaert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!