{"thread":{"id":"60121","subject":"clone (single) commit id?","startedAt":"2023-08-17T19:46:12Z","lastAt":"2023-08-17T21:40:09Z","messageCount":4,"participants":["Patrik Hägglund","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"480757","messageId":"CABtpZSGcL8hkk3HA3ECtt7KeLPOhuB0n7EKN1Tg5ZHpFBE0V0A@mail.gmail.com","threadId":"60121","inReplyTo":null,"subject":"clone (single) commit id?","fromName":"Patrik Hägglund","fromEmail":"patrik.h.hagglund@gmail.com","sentAt":"2023-08-17T19:45:19Z","receivedAt":"2023-08-17T19:46:12Z","isPatch":false,"sender":{"key":"patrik.h.hagglund@gmail.com","avatar":null},"body":"In our CI setup, for reproducibility and performance reasons, I want\nto be able to clone a repository with only a single given commit id\n(commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is\npossible, but more elaborate/low-level.)\n\nAt https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/\nit is stated that:\n\n> Never mind, I see, feature exists but server needs to allow it. Sigh.\n\nHowever, I'm not able to find this in the Git documentation. Can\nsomeone point out how to configure this? Can this be better\ndocumented?\n\n/Patrik Hägglund\n"},{"id":"480762","messageId":"20230817195641.GD3032779@coredump.intra.peff.net","threadId":"60121","inReplyTo":"CABtpZSGcL8hkk3HA3ECtt7KeLPOhuB0n7EKN1Tg5ZHpFBE0V0A@mail.gmail.com","subject":"Re: clone (single) commit id?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-08-17T19:56:41Z","receivedAt":"2023-08-17T19:57:36Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 17, 2023 at 09:45:19PM +0200, Patrik Hägglund wrote:\n\n> In our CI setup, for reproducibility and performance reasons, I want\n> to be able to clone a repository with only a single given commit id\n> (commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is\n> possible, but more elaborate/low-level.)\n> \n> At https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/\n> it is stated that:\n> \n> > Never mind, I see, feature exists but server needs to allow it. Sigh.\n> \n> However, I'm not able to find this in the Git documentation. Can\n> someone point out how to configure this? Can this be better\n> documented?\n\nI'd use a shallow clone with depth 1, like:\n\n  git clone -b $your_branch --depth 1 $remote_url\n\nNote that \"--depth\" implies --single-branch, so it will really just grab\nthat one branch (and if it's the remote's default branch that you want,\nyou can omit the \"-b $your_branch\" part).\n\nIf you find the shape of history useful (e.g., your CI wants to look at\njust new commits), you might also find partial clones useful. Something\nlike:\n\n  git clone --filter=blob:none $remote_url\n\nwill fetch all commits and trees, but only load blobs on-demand (so\nbasically whatever is needed to check out that tip commit). You can\npare it down further by switching to \"--filter=tree:0\", which will avoid\ntrees (but note that filling in trees when you need them is a bit more\nexpensive, since inherently you have to make a round-trip to the server\nfor each level of tree).\n\n-Peff\n"},{"id":"480765","messageId":"CABtpZSFT2BLJpeDwizZiXB8+tRRLqz+iAFuWaXAiwH_EgS5gag@mail.gmail.com","threadId":"60121","inReplyTo":"20230817195641.GD3032779@coredump.intra.peff.net","subject":"Re: clone (single) commit id?","fromName":"Patrik Hägglund","fromEmail":"patrik.h.hagglund@gmail.com","sentAt":"2023-08-17T20:20:20Z","receivedAt":"2023-08-17T20:21:15Z","isPatch":false,"sender":{"key":"patrik.h.hagglund@gmail.com","avatar":null},"body":"As said, I want to use a commit id for reproducability and\nperformance. The CI flow starts several jobs, all using the same\ncommit id. A remote branch may be updated, and therefore considered\nnot good (reproducible) enough as the reference here.\n\n(Regarding you proposal of using partial clones: Unfortunately, our\nremote server don't support filtering yet.)\n\nOn Thu, Aug 17, 2023 at 9:56 PM Jeff King <peff@peff.net> wrote:\n>\n> On Thu, Aug 17, 2023 at 09:45:19PM +0200, Patrik Hägglund wrote:\n>\n> > In our CI setup, for reproducibility and performance reasons, I want\n> > to be able to clone a repository with only a single given commit id\n> > (commit hash). (Using 'git init' + 'git fetch' + 'git checkout' is\n> > possible, but more elaborate/low-level.)\n> >\n> > At https://lore.kernel.org/git/MN2PR12MB3616C1F2E97A18547740651DF9E29@MN2PR12MB3616.namprd12.prod.outlook.com/\n> > it is stated that:\n> >\n> > > Never mind, I see, feature exists but server needs to allow it. Sigh.\n> >\n> > However, I'm not able to find this in the Git documentation. Can\n> > someone point out how to configure this? Can this be better\n> > documented?\n>\n> I'd use a shallow clone with depth 1, like:\n>\n>   git clone -b $your_branch --depth 1 $remote_url\n>\n> Note that \"--depth\" implies --single-branch, so it will really just grab\n> that one branch (and if it's the remote's default branch that you want,\n> you can omit the \"-b $your_branch\" part).\n>\n> If you find the shape of history useful (e.g., your CI wants to look at\n> just new commits), you might also find partial clones useful. Something\n> like:\n>\n>   git clone --filter=blob:none $remote_url\n>\n> will fetch all commits and trees, but only load blobs on-demand (so\n> basically whatever is needed to check out that tip commit). You can\n> pare it down further by switching to \"--filter=tree:0\", which will avoid\n> trees (but note that filling in trees when you need them is a bit more\n> expensive, since inherently you have to make a round-trip to the server\n> for each level of tree).\n>\n> -Peff\n"},{"id":"480768","messageId":"20230817213902.GA3036503@coredump.intra.peff.net","threadId":"60121","inReplyTo":"CABtpZSFT2BLJpeDwizZiXB8+tRRLqz+iAFuWaXAiwH_EgS5gag@mail.gmail.com","subject":"Re: clone (single) commit id?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-08-17T21:39:02Z","receivedAt":"2023-08-17T21:40:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 17, 2023 at 10:20:20PM +0200, Patrik Hägglund wrote:\n\n> As said, I want to use a commit id for reproducability and\n> performance. The CI flow starts several jobs, all using the same\n> commit id. A remote branch may be updated, and therefore considered\n> not good (reproducible) enough as the reference here.\n\nOh, sorry, I didn't realize that was the sticking point. No, sadly I\ndon't think there is any way to feed a direct oid to clone currently.\nClone does know how to end up on a detached HEAD (e.g., if you specify a\ntag with \"--branch\"). IMHO that would be a useful feature to learn, but\nI think most folks resort to init+fetch, since it's most often useful in\nscripted situations (like CI) anyway.\n\n-Peff\n"}]}