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

Re: How can I tell if a SHA1 is a submodule reference?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
May 15, 2008, 20:13 UTC
Message-ID
<alpine.LFD.1.10.0805151311050.3019@woody.linux-foundation.org>
In-Reply-To
<7F242E8F-13CF-4BE5-B3E6-85F285391658@ohloh.net>
On Thu, 15 May 2008, Robin Luckey wrote:
Show 17 quoted lines
>
> I am parsing the output of git-diff-tree to create some code analysis reports.
> 
> When a user adds a submodule to a repository, git-diff-tree reports the SHA1
> of the commit from the submodule.
> 
> However, if I subsequently try to pass this SHA1 to git-cat-file, or indeed
> any other git command I have tried, I receive an error:
> 
> error: unable to find b0f8c354b142e27333abd0f175544b71a0cc444e
> fatal: Not a valid object name b0f8c354b142e27333abd0f175544b71a0cc444e
> 
> This makes sense to me, since these objects are not stored locally; they are
> stored in the submodule repository.
> 
> However, is there a simple and reliable way for me to know which SHA1 hashes
> refer to such submodule objects? I'd like to simply ignore them.
Only if you still have the tree references they came from.

In other words, once you *only* have the SHA1, you're kind of screwed, because by that time you've lost the context, and the SHA1 itself contains no information about what kind of thing it is.

But when running git-diff-tree, you still have the source of the SHA1, and the tree entry in particular. The tree entry will have a "gitlink" marker, ie the "mode" will be 0160000.

			Linus
Previous: Avery PennarunNext: Junio C Hamano
Message 3 of 5 in “How can I tell if a SHA1 is a submodule reference?”
  1. Robin LuckeyMay 15, 2008
  2. Avery PennarunMay 15, 2008
  3. Linus TorvaldsMay 15, 2008
  4. Junio C HamanoMay 15, 2008
  5. Robin LuckeyMay 15, 2008

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.