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

Fetching a specific commit by commit ID

From
OCOlivier Croquette <ocroquette@free.fr>
Date
Dec 6, 2014, 12:39 UTC
Message-ID
<0EA82B66-7DDD-40A9-BB9C-94D3B1B43DBB@free.fr>
Hello everyone,
I am trying to fetch a commit using a commit ID instead of a reference. According to the documentation of git-fetch, this is not supported, but I found out that this is not entirely true.
If the commit is already available in the repository, I get:
$ git fetch origin 7365b1a9bd45fbf12b09381d5779b607e232a8cd
From repo1
 * branch            7365b1a9bd45fbf12b09381d5779b607e232a8cd -> FETCH_HEAD
$ echo $?
0

If the commit is not in the repository (but it is present in the remote of course), I get: $ git fetch origin fc907b94f69b9bd710ba55b5522258b722fefb3b $ echo $? 1

That brings up following questions/remarks:
- the documentation of git-fetch is not entirely correct, commit ids are partially supported, not only refs
- “git fetch origin fc907” should print an error message on STDERR specifying what the problem is
- more interestingly: is there any reason why git fetch should not support fetching by commit id? There are real world use cases where this can be very useful, for instance when references on the remote have been overwritten or deleted.
Olivier
Next: brian m. carlson
Message 1 of 3 in “Fetching a specific commit by commit ID”
  1. Olivier CroquetteDec 6, 2014
  2. brian m. carlsonDec 6, 2014
  3. Olivier CroquetteDec 7, 2014

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.