git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* cannot clone --single-commit instead of --single-branch
@ 2019-08-01 20:52 Alexander Mills
  2019-08-01 22:40 ` Bryan Turner
  2019-08-02  2:57 ` Jonathan Nieder
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Mills @ 2019-08-01 20:52 UTC (permalink / raw)
  To: git

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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cannot clone --single-commit instead of --single-branch
  2019-08-01 20:52 cannot clone --single-commit instead of --single-branch Alexander Mills
@ 2019-08-01 22:40 ` Bryan Turner
  2019-08-02  2:43   ` Jonathan Nieder
  2019-08-02  2:57 ` Jonathan Nieder
  1 sibling, 1 reply; 5+ messages in thread
From: Bryan Turner @ 2019-08-01 22:40 UTC (permalink / raw)
  To: Alexander Mills; +Cc: Git Users

On Thu, Aug 1, 2019 at 1:52 PM Alexander Mills
<alexander.d.mills@gmail.com> wrote:
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cannot clone --single-commit instead of --single-branch
  2019-08-01 22:40 ` Bryan Turner
@ 2019-08-02  2:43   ` Jonathan Nieder
  2019-08-02  3:07     ` Mike Hommey
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Nieder @ 2019-08-02  2:43 UTC (permalink / raw)
  To: Bryan Turner; +Cc: Alexander Mills, Git Users

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cannot clone --single-commit instead of --single-branch
  2019-08-01 20:52 cannot clone --single-commit instead of --single-branch Alexander Mills
  2019-08-01 22:40 ` Bryan Turner
@ 2019-08-02  2:57 ` Jonathan Nieder
  1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Nieder @ 2019-08-02  2:57 UTC (permalink / raw)
  To: Alexander Mills; +Cc: git, Nguyễn Thái Ngọc Duy, Bryan Turner

(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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cannot clone --single-commit instead of --single-branch
  2019-08-02  2:43   ` Jonathan Nieder
@ 2019-08-02  3:07     ` Mike Hommey
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Hommey @ 2019-08-02  3:07 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Bryan Turner, Alexander Mills, Git Users

On Thu, Aug 01, 2019 at 07:43:22PM -0700, Jonathan Nieder wrote:
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-02  3:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 20:52 cannot clone --single-commit instead of --single-branch Alexander Mills
2019-08-01 22:40 ` Bryan Turner
2019-08-02  2:43   ` Jonathan Nieder
2019-08-02  3:07     ` Mike Hommey
2019-08-02  2:57 ` Jonathan Nieder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).