git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Shallow clone of a specific git revision?

From
David Aguilar <davvid@gmail.com>
Date
Nov 15, 2024, 05:00 UTC
Message-ID
<ZzbVe79p_Zbnb6rs@gmail.com>
In-Reply-To
<ZzR_nOqQxfGNPyYV@kitsune.suse.cz>
On Wed, Nov 13, 2024 at 11:29:48AM +0100, Michal Suchánek wrote:
Show 27 quoted lines
> On Wed, Nov 13, 2024 at 11:23:47AM +0100, Toon Claes wrote:
> > Michal Suchánek <msuchanek@suse.de> writes:
> > 
> > > Hello,
> > >
> > > Looking through clone man page it supports shallow clones of branches
> > > and tags only.
> > >
> > > Would it be possible to do shallow clone of a specific revision,
> > > and checkout specific revision on clone?
> > 
> > Hi Michal,
> > 
> > I'm working on a patch, and I've submitted a first version [1] a little
> > while ago to allow users to pass a reference on git-clone(1). Would this
> > change fit your needs, or what else would you like to support?
> 
> > [1]: https://lore.kernel.org/git/20240927085438.1010431-1-toon@iotcl.com/
> 
> Hello,
> 
> that slightly expands the available options but it does not make it
> possible to clone an arbitrary revision, ie. specified by a SHA
> 
> Thanks
> 
> Michal

In case it helps, here's a short recipe demonstrating how to do a shallow "clone" of a specific commit ID:

    git init the-repo
    cd ./the-repo
    git remote add origin <url>
    git fetch --depth=1 origin <commit-id>
    git checkout <commit-id>
It'd be nice to add this feature to "git clone" for convenience.

This recipe depends on the server's configuration. You must have one of the following configuration variables set "true" server-side in order for the server to accept requests for arbitrary commit IDs:

    uploadpack.allowReachableSHA1InWant
        Allow upload-pack to accept a fetch request that asks for an
        object that is reachable from any ref tip. However, note that
        calculating object reachability is computationally expensive.
        Defaults to false. Even if this is false, a client may be able
        to steal objects via the techniques described in the "SECURITY"
        section of the gitnamespaces(7) man page; it’s best to keep
        private data in a separate repository.
    uploadpack.allowAnySHA1InWant
        Allow upload-pack to accept a fetch request that asks for any
        object at all. Defaults to false.
cheers,
-- 
David
Previous: Michal SuchánekNext: Jeff King
Message 4 of 6 in “Shallow clone of a specific git revision?”
  1. Michal SuchánekNov 12, 2024
  2. Toon ClaesNov 13, 2024
  3. Michal SuchánekNov 13, 2024
  4. David AguilarNov 15, 2024
  5. Jeff KingNov 15, 2024
  6. Michal SuchánekNov 15, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.