git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* clone (single) commit id?
@ 2023-08-17 19:45 Patrik Hägglund
  2023-08-17 19:56 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Patrik Hägglund @ 2023-08-17 19:45 UTC (permalink / raw)
  To: git

In our CI setup, for reproducibility and performance reasons, I want
to be able to clone a repository with only a single given commit id
(commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is
possible, but more elaborate/low-level.)

At https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/
it is stated that:

> Never mind, I see, feature exists but server needs to allow it. Sigh.

However, I'm not able to find this in the Git documentation. Can
someone point out how to configure this? Can this be better
documented?

/Patrik Hägglund

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

* Re: clone (single) commit id?
  2023-08-17 19:45 clone (single) commit id? Patrik Hägglund
@ 2023-08-17 19:56 ` Jeff King
  2023-08-17 20:20   ` Patrik Hägglund
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2023-08-17 19:56 UTC (permalink / raw)
  To: Patrik Hägglund; +Cc: git

On Thu, Aug 17, 2023 at 09:45:19PM +0200, Patrik Hägglund wrote:

> In our CI setup, for reproducibility and performance reasons, I want
> to be able to clone a repository with only a single given commit id
> (commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is
> possible, but more elaborate/low-level.)
> 
> At https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/
> it is stated that:
> 
> > Never mind, I see, feature exists but server needs to allow it. Sigh.
> 
> However, I'm not able to find this in the Git documentation. Can
> someone point out how to configure this? Can this be better
> documented?

I'd use a shallow clone with depth 1, like:

  git clone -b $your_branch --depth 1 $remote_url

Note that "--depth" implies --single-branch, so it will really just grab
that one branch (and if it's the remote's default branch that you want,
you can omit the "-b $your_branch" part).

If you find the shape of history useful (e.g., your CI wants to look at
just new commits), you might also find partial clones useful. Something
like:

  git clone --filter=blob:none $remote_url

will fetch all commits and trees, but only load blobs on-demand (so
basically whatever is needed to check out that tip commit). You can
pare it down further by switching to "--filter=tree:0", which will avoid
trees (but note that filling in trees when you need them is a bit more
expensive, since inherently you have to make a round-trip to the server
for each level of tree).

-Peff

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

* Re: clone (single) commit id?
  2023-08-17 19:56 ` Jeff King
@ 2023-08-17 20:20   ` Patrik Hägglund
  2023-08-17 21:39     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Patrik Hägglund @ 2023-08-17 20:20 UTC (permalink / raw)
  To: Jeff King; +Cc: git

As said, I want to use a commit id for reproducability and
performance. The CI flow starts several jobs, all using the same
commit id. A remote branch may be updated, and therefore considered
not good (reproducible) enough as the reference here.

(Regarding you proposal of using partial clones: Unfortunately, our
remote server don't support filtering yet.)

On Thu, Aug 17, 2023 at 9:56 PM Jeff King <peff@peff.net> wrote:
>
> On Thu, Aug 17, 2023 at 09:45:19PM +0200, Patrik Hägglund wrote:
>
> > In our CI setup, for reproducibility and performance reasons, I want
> > to be able to clone a repository with only a single given commit id
> > (commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is
> > possible, but more elaborate/low-level.)
> >
> > At https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/
> > it is stated that:
> >
> > > Never mind, I see, feature exists but server needs to allow it. Sigh.
> >
> > However, I'm not able to find this in the Git documentation. Can
> > someone point out how to configure this? Can this be better
> > documented?
>
> I'd use a shallow clone with depth 1, like:
>
>   git clone -b $your_branch --depth 1 $remote_url
>
> Note that "--depth" implies --single-branch, so it will really just grab
> that one branch (and if it's the remote's default branch that you want,
> you can omit the "-b $your_branch" part).
>
> If you find the shape of history useful (e.g., your CI wants to look at
> just new commits), you might also find partial clones useful. Something
> like:
>
>   git clone --filter=blob:none $remote_url
>
> will fetch all commits and trees, but only load blobs on-demand (so
> basically whatever is needed to check out that tip commit). You can
> pare it down further by switching to "--filter=tree:0", which will avoid
> trees (but note that filling in trees when you need them is a bit more
> expensive, since inherently you have to make a round-trip to the server
> for each level of tree).
>
> -Peff

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

* Re: clone (single) commit id?
  2023-08-17 20:20   ` Patrik Hägglund
@ 2023-08-17 21:39     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2023-08-17 21:39 UTC (permalink / raw)
  To: Patrik Hägglund; +Cc: git

On Thu, Aug 17, 2023 at 10:20:20PM +0200, Patrik Hägglund wrote:

> As said, I want to use a commit id for reproducability and
> performance. The CI flow starts several jobs, all using the same
> commit id. A remote branch may be updated, and therefore considered
> not good (reproducible) enough as the reference here.

Oh, sorry, I didn't realize that was the sticking point. No, sadly I
don't think there is any way to feed a direct oid to clone currently.
Clone does know how to end up on a detached HEAD (e.g., if you specify a
tag with "--branch"). IMHO that would be a useful feature to learn, but
I think most folks resort to init+fetch, since it's most often useful in
scripted situations (like CI) anyway.

-Peff

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

end of thread, other threads:[~2023-08-17 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-17 19:45 clone (single) commit id? Patrik Hägglund
2023-08-17 19:56 ` Jeff King
2023-08-17 20:20   ` Patrik Hägglund
2023-08-17 21:39     ` Jeff King

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 NNTP newsgroup(s).