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

git diff <file> HEAD^:<file> error message

From
Carlos Martín Nieto <cmn@elego.de>
Date
Jan 11, 2012, 11:18 UTC
Message-ID
<20120111111831.GB15232@beez.lab.cmartin.tk>
Hello,
I was trying to figure out why running
   git diff HEAD^:RelNotes RelNotes

gives the expected output (on maint it tells me that the stable version changed from 1.7.8.3 to 1.7.8.4) but swapping the arguments doesn't.

   git diff RelNotes HEAD^:RelNotes

doesn't show the opposite patch but tells me that RelNotes doesn't exist in HEAD^ which is clearly a lie (it sounds like it's a misunderstanding on git's part, but it's certainly not the truth). In both cases, verify_filename gets called and tries to stat both HEAD^:RelNotes and RelNotes. In the "bad" (latter) case, after it fails to find a file named "HEAD^:RelNotes" it ends up calling diagnose_invalid_sha1_path which is not correct according to the command just before the function

    /* Must be called only when object_name:filename doesn't exist. */

It looks like get_sha1_with_context_1 gets confused because we pass it a filename which looks like object_name:filename even though we earlier parsed it simply as a filename which happens to have a colon inside it.

Another issue is that I'm not sure that the error message should even get shown. The documentation tells me that I should be able to compare two random blobs, though this mode doesn't seem to work if the first argument is a file. I realise that a file isn't a blob, but since specifying the arguments the other way around (blob, file) does work, it looks to me like it should as well.

   cmn
Next: Junio C Hamano
Message 1 of 4 in “git diff <file> HEAD^:<file> error message”
  1. Carlos Martín NietoJan 11, 2012
  2. Junio C HamanoJan 12, 2012
  3. Carlos Martín NietoJan 12, 2012
  4. Nguyen Thai Ngoc DuyJan 12, 2012

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.