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

Re: suggested feature: someone mails me a blob, git please tell me what it is

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 16, 2007, 17:37 UTC
Message-ID
<Pine.LNX.4.64.0702160930130.20368@woody.linux-foundation.org>
In-Reply-To
<vpqr6sq58j8.fsf@olympe.imag.fr>
On Fri, 16 Feb 2007, Matthieu Moy wrote:
> 
> But it should be possible to recompute the git sha1sum by recomputing
> the magic formula sha1sum(<ascii type without space> + <space> +
> <ascii decimal size> + <byte\0> + <binary object data>).
Yes. Try this:
	[torvalds@woody git]$ ls -l Makefile
	-rw-rw-rw- 1 torvalds torvalds 27586 Feb 14 13:35 Makefile
	[torvalds@woody git]$ ( echo -en "blob 27586\0" ; cat Makefile ) | sha1sum
	ebecbbd9c28390654ed9fea2ff4ebf6a5a317c70  -
	[torvalds@woody git]$ git ls-tree HEAD Makefile
	100644 blob ebecbbd9c28390654ed9fea2ff4ebf6a5a317c70    Makefile
and notice how the SHA1's match (ebecbb..).

Now, finding all of the copies of that particular object in history is pretty expensive. You'll basically have to do something like

	git rev-list --all |
		while read i
		do
			files=$(git ls-tree -r $i | grep $SHA1)
			if [ -n "$files" ]
			then
				git cat-file -p $i
				echo $files
				echo
			fi
		done

which is quite expensive. You can probably start from "git fsck" and ask it to print out where it found something (but then it will print out only the first time it found it - because it avoids walking trees more than once it won't report on it unless if finds it in two trees that are different).

			Linus
Previous: Matthieu MoyNext: Shawn O. Pearce
Message 4 of 6 in “suggested feature: someone mails me a blob, git please tell me what it is”
  1. Mike ColemanFeb 16, 2007
  2. Nicolas PitreFeb 16, 2007
  3. Matthieu MoyFeb 16, 2007
  4. Linus TorvaldsFeb 16, 2007
  5. Shawn O. PearceFeb 17, 2007
  6. Andy ParkinsFeb 17, 2007

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.