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

Re: git with custom diff for commits

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Dec 18, 2007, 21:51 UTC
Message-ID
<vpqsl1zfz8r.fsf@bauges.imag.fr>
In-Reply-To
<000101c841b7$5f1d1060$762a14ac@na.acco.com>
"Gerald Gutierrez" <ggmlfs@gmail.com> writes:
> Yes, but wouldn't it be slick to actually teach git's internal diff to do
> things like GNU diff can, like the ignore option -I, case insensitivity,
> etc. I thought that's what the external diff capability is for, but it is
> not so.
Don't confuse diff and commit.

Git is really snapshot oriented. When you commit, you don't say "record the changes I made since HEAD", you say "record the current state of the working tree, and also record the fact that this state is based on HEAD".

See what a commit object looks like:

$ git cat-file -p 183f84365d tree 3f9d576b4adc78188a411104bc21159d459fa3f4 parent b9c506f7d9f05a630fa7e31b77a9cf5081d7dbba author Shun Kei Leung <kevinlsk@gmail.com> 1195614079 +0800 committer Junio C Hamano <gitster@pobox.com> 1195630064 -0800

git-p4: Fix typo in --detect-labels
Signed-off-by: Kevin Leung <kevinlsk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
$ _

The "tree" tells you the state of the project as recorded by commit, and the "parent" tells you where the HEAD was pointing to at commit time. That's really the raw information recorded by git.

Now, "diff" comes into the picture for two things: 1) storage efficiency (you prefer a 1Mb pack file to a 1Gb uncompressed repository), but that doesn't change the concept, and 2) user interface.

When you say "git show HEAD", for example, git will recompute a diff, and show it to you because this is what you expect. But this information is computed at "git show" time, not at "git commit" time.

What you seem to expect is to tell git "commit the changes except this portion", what you have to tell git is actually "commit the new state, but not if this portion is the only change". That sounds identical, but it's actually a bit different.

-- 
Matthieu
Previous: Junio C HamanoNext: Gerald Gutierrez
Message 15 of 24 in “git with custom diff for commits”
  1. Gerald GutierrezDec 17, 2007
  2. Johannes SchindelinDec 17, 2007
  3. Matthieu MoyDec 17, 2007
  4. Johannes SchindelinDec 17, 2007
  5. Junio C HamanoDec 17, 2007
  6. Matthieu MoyDec 18, 2007
  7. Junio C HamanoDec 18, 2007
  8. Gerald GutierrezDec 18, 2007
  9. Junio C HamanoDec 18, 2007
  10. Gerald GutierrezDec 18, 2007
  11. Johannes SchindelinDec 18, 2007
  12. Gerald GutierrezDec 18, 2007
  13. Johannes SchindelinDec 18, 2007
  14. Junio C HamanoDec 18, 2007
  15. Matthieu MoyDec 18, 2007
  16. Gerald GutierrezDec 18, 2007
  17. Johannes SchindelinDec 18, 2007
  18. Martin LanghoffDec 18, 2007
  19. Matthieu MoyDec 19, 2007
  20. Johannes SchindelinDec 19, 2007
  21. Matthieu MoyDec 19, 2007
  22. Matthieu MoyDec 19, 2007
  23. Gerald GutierrezDec 18, 2007
  24. Gerald GutierrezDec 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.