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

Re: Fetching commit instead of ref

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Dec 18, 2017, 18:16 UTC
Message-ID
<20171218101655.16105728beb82d38732e48a0@google.com>
In-Reply-To
<1513600223353.28799@arris.com>

On Mon, 18 Dec 2017 12:30:23 +0000 "Carlsson, Magnus" <Magnus.Carlsson@arris.com> wrote:

> In a certain situation I would really need to fetch all commits
> related to a specific commit (SHA). I have read the git fetch
> documentation and found nothing regarding this. It only seems to
> support fetching references.

The documentation has been updated in version 2.15.0 to describe this. But as the commit message of commit 83558a412afa ("fetch doc: src side of refspec could be full SHA-1", 2017-10-18) says, this functionality was available earlier.

Show 14 quoted lines
> I found some traces on stack overflow:
> https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository
> 
> Following that recommendation it feels like it almost works:
> $ git fetch subrepo 50f730db793e0733b159326c5a3e78fd48cedfec:refs/remote/subrepo/foo-commit
> remote: Counting objects: 2311, done.
> remote: Total 2311 (delta 0), reused 0 (delta 0), pack-reused 2311
> Receiving objects: 100% (2311/2311), 703.64 KiB | 0 bytes/s, done.
> Resolving deltas: 100% (1174/1174), done.
> ----> So far so good, but then an error message appear:
> error: Server does not allow request for unadvertised object 50f730db793e0733b159326c5a3e78fd48cedfec
> ----> And nothing seems to be fetched.
> 
> Is there a way to fetch a commit and any ancestors to that commit based on a SHA?

You'll need to set uploadpack.allowTipSHA1InWant, uploadpack.allowReachableSHA1InWant, or uploadpack.allowAnySHA1InWant on the server. (This might need to be better documented - I see this documented for fetch-pack, but not fetch.)

Previous: Carlsson, MagnusNext: Stefan Beller
Message 2 of 8 in “Fetching commit instead of ref”
  1. Carlsson, MagnusDec 18, 2017
  2. Jonathan TanDec 18, 2017
  3. Stefan BellerDec 18, 2017
  4. Junio C HamanoDec 18, 2017
  5. Carlsson, MagnusDec 19, 2017
  6. Junio C HamanoDec 19, 2017
  7. Carlsson, MagnusDec 20, 2017
  8. Junio C HamanoDec 22, 2017

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.