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

Can I fetch an arbitrary commit by sha1?

From
Christian Halstrick <christian.halstrick@gmail.com>
Date
Oct 2, 2014, 13:57 UTC
Message-ID
<CAENte7htO13s91UJFNzW4aBhsGxE=LpnvaZfce+vqQU5+a-cYg@mail.gmail.com>

I always though during fetch I have to specify a refspec and that a sha1 would not be accepted as a ref. Firing some like 'git fetch origin <sha1>' should be forbidden. But in fact I see that such a fetch command succeeds if you already have that object in your local repo.

My question: is it allowed to fetch sha1's? Shouldn't fetch fail if you try it?
See here:
> git clone -q https://github.com/chalstrick/dondalfi.git
> cd dondalfi
> git ls-remote

From https://github.com/chalstrick/dondalfi.git ce08dcc41104383f3cca2b95bd41e9054a957f5b HEAD af00f4c39bcc8dc29ed8f59a47066d5993c279e4 refs/foo/b1 ...

> git show af00f4c39bcc8dc29ed8f59a47066d5993c279e4
fatal: bad object af00f4c39bcc8dc29ed8f59a47066d5993c279e4
> git fetch origin af00f4c39bcc8dc29ed8f59a47066d5993c279e4
error: no such remote ref af00f4c39bcc8dc29ed8f59a47066d5993c279e4
> git fetch origin refs/foo/b1
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://github.com/chalstrick/dondalfi
 * branch            refs/foo/b1 -> FETCH_HEAD
> git fetch origin af00f4c39bcc8dc29ed8f59a47066d5993c279e4
From https://github.com/chalstrick/dondalfi
 * branch            af00f4c39bcc8dc29ed8f59a47066d5993c279e4 -> FETCH_HEAD
Ciao
  Chris
Next: Dan Johnson
Message 1 of 12 in “Can I fetch an arbitrary commit by sha1?”
  1. Christian HalstrickOct 2, 2014
  2. Dan JohnsonOct 2, 2014
  3. Jeff KingOct 2, 2014
  4. Jonathan NiederOct 2, 2014
  5. Christian HalstrickOct 5, 2014
  6. Patrick DonnellyOct 6, 2014
  7. David LangOct 6, 2014
  8. Duy NguyenOct 7, 2014
  9. Duy NguyenOct 7, 2014
  10. Junio C HamanoOct 7, 2014
  11. Duy NguyenOct 8, 2014
  12. Junio C HamanoOct 9, 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.