threads / discuss / 49314

Is it possible to git clone --filter= without any objects?

Subject: Is it possible to git clone --filter= without any objects?

## tl;dr

6 messages between Sep 11, 2018 and Sep 12, 2018.

replies: 5people: 5as markdown or json

Ciro Santilli· Sep 11, 2018, 07:29 UTC · lore

At v2.19.0 I was trying to clone a fetch just a single directory: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934

I got really close with:
git clone --depth 1 --no-checkout --filter=blob:none \
  "file://$(pwd)/server_repo" local_repo
cd local_repo
git checkout master -- mydir/
The only missing thing is that uneeded tree objects are still being fetched.
If I had a:
git clone --filter=none
for example then that would be done.

Nothing major since those are small, but just looking for the perfect command :-)

Stefan Beller· Sep 11, 2018, 17:15 UTC · re: Ciro Santilli · lore

Re: Is it possible to git clone --filter= without any objects?

On Tue, Sep 11, 2018 at 12:29 AM Ciro Santilli <ciro.santilli@gmail.com> wrote:
Show 21 quoted lines
>
> At v2.19.0 I was trying to clone a fetch just a single directory:
> https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
>
> I got really close with:
>
> git clone --depth 1 --no-checkout --filter=blob:none \
>   "file://$(pwd)/server_repo" local_repo
> cd local_repo
> git checkout master -- mydir/
>
> The only missing thing is that uneeded tree objects are still being fetched.
>
> If I had a:
>
> git clone --filter=none
>
> for example then that would be done.
>
> Nothing major since those are small, but just looking for the perfect
> command :-)

You might be pleased to hear about a series floating on the mailing list, that started at https://public-inbox.org/git/cover.1533854545.git.matvore@google.com/ and promised to filter trees away, and its latest version can be found at https://public-inbox.org/git/cover.1536081438.git.matvore@google.com/

Thanks, Stefan

Jonathan Tan· Sep 11, 2018, 17:19 UTC · re: Stefan Beller · lore

Re: Is it possible to git clone --filter= without any objects?

On Tue, Sep 11, 2018 at 10:15 AM, Stefan Beller <sbeller@google.com> wrote:
Show 5 quoted lines
> You might be pleased to hear about a series floating on the mailing list,
> that started at
> https://public-inbox.org/git/cover.1533854545.git.matvore@google.com/
> and promised to filter trees away, and its latest version can be found at
> https://public-inbox.org/git/cover.1536081438.git.matvore@google.com/

I mentioned this in an email to the original poster in which I forgot to also CC the mailing list:

By "without any objects" in your email subject, do you mean "without blob and tree objects"? If yes, there is some code in the md/filter-trees branch that can do that with a "--filter=tree:0" option. As far as I know, it is not yet in any released version of Git, but hopefully will be in the next one (the "What's Cooking" [1] email mentions that it will be merged to the "next" branch, which is one of the steps before it is released).

[1] https://public-inbox.org/git/xmqqmusw6gbo.fsf@gitster-ct.c.googlers.com/
Junio C Hamano· Sep 11, 2018, 17:46 UTC · re: Jonathan Tan · lore

Re: Is it possible to git clone --filter= without any objects?

Jonathan Tan <jonathantanmy@google.com> writes:
> By "without any objects" in your email subject, do you mean "without
> blob and tree objects"? If yes, there is some code in the
> md/filter-trees branch that can do that with a "--filter=tree:0"
> option.

I too was wondering what the "without any objects" thing meant myself.

What would it take on top of the following sequence to create such an ultra-lazy clone?

	$ mkdir very-sparse && cd very-sparse
	$ git init
	$ git remote add origin $URL

At this point, the repository does not have any object, but it already knows whom to talk to to get the objects in the project. The remote must be configured so that it is willing to feed you any object you name, but would it be just some "git config" magic after the above three steps to make it as if it was prepared with "git clone --filter="? If so, what does that magic look like?

Thanks.
Ciro Santilli· Sep 11, 2018, 18:29 UTC · re: Junio C Hamano · lore

Re: Is it possible to git clone --filter= without any objects?

On Tue, Sep 11, 2018 at 6:47 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
>
> Jonathan Tan <jonathantanmy@google.com> writes:
>
> > By "without any objects" in your email subject, do you mean "without
> > blob and tree objects"? If yes, there is some code in the
> > md/filter-trees branch that can do that with a "--filter=tree:0"
> > option.
>
> I too was wondering what the "without any objects" thing meant
> myself.
>

Thanks for all replies, as you correctly deduced, I meant "without fetching any objects".

The mentioned --filter=tree:0 would basically do what I want it seems, good to hear!. I wonder why not call it tree:none though to match blob:none.

Show 7 quoted lines
> What would it take on top of the following sequence to create such
> an ultra-lazy clone?
>
>         $ mkdir very-sparse && cd very-sparse
>         $ git init
>         $ git remote add origin $URL
>

Yes, this would be a good CLI API since the since the clone --no-checkout --filter --filter gets a bit long.

Or maybe:

git clone --lazy URL repo_local cd repo_local git checkout commit -- path/within/repo

Or maybe even:
git clene --lazy URL repo_local COMMITISH path/within/repo
to do both in one go.
People are also interested in commit-less directory / file "clones"
BTW: https://stackoverflow.com/questions/2466735/how-to-checkout-only-one-file-from-git-repository-sparse-checkout
Show 8 quoted lines
> At this point, the repository does not have any object, but it
> already knows whom to talk to to get the objects in the project.
> The remote must be configured so that it is willing to feed you any
> object you name, but would it be just some "git config" magic after
> the above three steps to make it as if it was prepared with "git
> clone --filter="?  If so, what does that magic look like?
>
> Thanks.
Matthew DeVore· Sep 12, 2018, 01:12 UTC · re: Ciro Santilli · lore

Re: Is it possible to git clone --filter= without any objects?

On Tue, Sep 11, 2018 at 11:30 AM Ciro Santilli <ciro.santilli@gmail.com> wrote:
> The mentioned --filter=tree:0 would basically do what I want it seems,
> good to hear!. I wonder why not call it tree:none though to match
> blob:none.

There are some plans of making tree: accept positive integers in order to filter out files greater than that depth. e.g. tree:1 would fetch all blobs and tree objects directly contained by the tree. tree:2 would fetch every object tree:1 does plus anything referred to directly by those objects.

← back to recent threads