threads / discuss / 51571

cannot clone --single-commit instead of --single-branch

Subject: cannot clone --single-commit instead of --single-branch

## tl;dr

5 messages between Aug 1, 2019 and Aug 2, 2019.

replies: 4people: 4as markdown or json

Alexander Mills· Aug 1, 2019, 20:52 UTC · lore
Looking for help with this problem:
https://stackoverflow.com/questions/57316783/git-clone-single-branch-does-not-work-for-sha-commit-ids
Essentially looking for:
git clone --single-commit
since
git clone --single-branch=<sha>

doesn't seem to work? any help appreciated.

-alex
-- 
Alexander D. Mills
New cell phone # (415)730-1805
alexander.d.mills@gmail.com

www.linkedin.com/pub/alexander-mills/b/7a5/418/
Bryan Turner· Aug 1, 2019, 22:40 UTC · re: Alexander Mills · lore

Re: cannot clone --single-commit instead of --single-branch

On Thu, Aug 1, 2019 at 1:52 PM Alexander Mills <alexander.d.mills@gmail.com> wrote:

Show 8 quoted lines
>
> Looking for help with this problem:
>
> https://stackoverflow.com/questions/57316783/git-clone-single-branch-does-not-work-for-sha-commit-ids
>
> Essentially looking for:
>
> git clone --single-commit

There's no such option, which will be why it doesn't work. I suspect the closest feature is a shallow clone, performed using git clone --depth=1. That's still not going to allow passing an arbitrary SHA-1, though; it'll only support a branch name, the same as --single-branch, which --depth implies (unless --no-single-branch is specified, at which point it fetches the depth for all branches).

Promisor remotes and other in-flight changes might help provide some of what you're looking for, but I'm not aware of any already-available solution. Perhaps something like VFS for Git, if whatever hosting solution you're using supports it.

Hope this helps! Bryan

Jonathan Nieder· Aug 2, 2019, 02:43 UTC · re: Bryan Turner · lore

Re: cannot clone --single-commit instead of --single-branch

Hi,
Bryan Turner wrote:
> Promisor remotes and other in-flight changes might help provide some
> of what you're looking for, but I'm not aware of any already-available
> solution.
You can do
	git clone --no-checkout --filter=blob:none $url repo
	cd repo
	git checkout $commit

That gives you commits and trees from other commits, but the only blobs it downloads are from the named commit.

Using the existing tree filtering features to limit the trees fetched and/or writing a patch for commit filtering are left as exercises to the reader.

Thanks and hope that helps, Jonathan

Mike Hommey· Aug 2, 2019, 03:07 UTC · re: Jonathan Nieder · lore

Re: cannot clone --single-commit instead of --single-branch

On Thu, Aug 01, 2019 at 07:43:22PM -0700, Jonathan Nieder wrote:
Show 11 quoted lines
> Hi,
> 
> Bryan Turner wrote:
> 
> > Promisor remotes and other in-flight changes might help provide some
> > of what you're looking for, but I'm not aware of any already-available
> > solution.
> 
> You can do
> 
> 	git clone --no-checkout --filter=blob:none $url repo
TIL. Why doesn't --filter appear in the git-clone manual page?
Mike
Jonathan Nieder· Aug 2, 2019, 02:57 UTC · re: Alexander Mills · lore

Re: cannot clone --single-commit instead of --single-branch

(cc: Duy, who might enjoy this walk through history) Hi,

Alexander Mills wrote:
> git clone --single-branch=<sha>
>
> doesn't seem to work?

I've occasionally wanted something like this (actually, I've wanted to pass a refname like "refs/meta/config"). builtin/clone.c contains

	static struct ref *find_remote_branch(const struct ref *refs, const char *branch)
	{
		struct ref *ref;
		struct strbuf head = STRBUF_INIT;
		strbuf_addstr(&head, "refs/heads/");
		strbuf_addstr(&head, branch);
		ref = find_ref_by_name(refs, head.buf);
		strbuf_release(&head);
		if (ref)
			return ref;
So far, what one would expect.
		strbuf_addstr(&head, "refs/tags/");
		strbuf_addstr(&head, branch);
		ref = find_ref_by_name(refs, head.buf);
		strbuf_release(&head);

Wait a second: a tag isn't a branch, so why do we accept it as a value for --branch? So this is stretching definitions a little already.

"git log -L:find_remote_branch:builtin/clone.c" tells me this is from v1.7.10-rc0~125^2~3 (clone: allow --branch to take a tag, 2012-01-16):

	Because a tag ref cannot be put to HEAD, HEAD will become detached.
	This is consistent with "git checkout <tag>".

I think ideally we could first check for a sha1 and then try the full set of patterns from ref_rev_parse_rules. What do you think? Would you be interested in taking a stab at it?

Thanks, Jonathan

← back to recent threads