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

Re: checking sha1's of files

From
Jeff King <peff@peff.net>
Date
Feb 8, 2009, 12:27 UTC
Message-ID
<20090208122731.GA24442@coredump.intra.peff.net>
In-Reply-To
<81bfc67a0902080422s7f12d86ft5196c184c06385f9@mail.gmail.com>
On Sun, Feb 08, 2009 at 07:22:31AM -0500, Caleb Cushing wrote:
Show 6 quoted lines
> >  $ git hash-object --stdin < Makefile
> >  27b9569746179e68c635bdaab8e57395f63faf01
> 
> is there anyway built in way to do that and check to see if the hash
> matches HEAD? (before I go and write a string comparison so that it
> does)
If you want to know whether a file matches HEAD, just do:
  git diff --quiet HEAD -- $LIST_OF_FILES
which will return '0' for no changes or '1' if there are changes.

Which really has nothing to do with hashes at all (though git will use them internally to avoid actually running a textual diff at all). I was assuming that you didn't necessarily _have_ the git repository at verification time. So the hash becomes an easy way of saying "this is what the file _should_ look like".

But again, I'm not sure I really understand the workflow you're trying to perform.

-Peff
Previous: Caleb CushingNext: Caleb Cushing
Message 6 of 7 in “checking sha1's of files”
  1. Caleb CushingFeb 8, 2009
  2. Junio C HamanoFeb 8, 2009
  3. Caleb CushingFeb 8, 2009
  4. Jeff KingFeb 8, 2009
  5. Caleb CushingFeb 8, 2009
  6. Jeff KingFeb 8, 2009
  7. Caleb CushingFeb 8, 2009

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.