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

Re: my git problem

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 28, 2008, 19:21 UTC
Message-ID
<alpine.LFD.1.10.0804281200130.3119@woody.linux-foundation.org>
In-Reply-To
<20080428114509.240ef4ae.akpm@linux-foundation.org>
On Mon, 28 Apr 2008, Andrew Morton wrote:
Show 8 quoted lines
> 
> hm, weirdness.
> 
> y:/usr/src/git26> git-diff origin...git-ia64   
> y:/usr/src/git26> git-log origin...git-ia64 | wc -l
> 15574
> 
> I'd have expected git-log to operate on the same patches as git-diff.
No, not at all.
 - "git log" shows each commit in a range.
 - "git diff" shows just the difference between two states.

The two have nothing in common. One operates on lots of individual commits (git log) individually, while the other one fundamentally operates on just two end-points (git diff).

And "a..b" and "a...b" means two totally different things for the two totally different operations.

When doing "a..b" and looking at individual commits, it means "show all commits that are in b but *not* in a". And when doing "a..b" when asking for a "diff", it means "show the difference from 'a' to 'b'".

They are *very* different operations indeed. The log can be empty, even if the diff is not empty (example: b is _before_ a, so there is nothing in 'b' that isn't in 'a', but that doesn't mean that 'b' is *equal* to 'a', so there is still a diff!). And the log can be non-empty, even if the diff is empty (example: 'b' and 'a' have the same actual tree, but two different ways of gettign there: the diff is empty, but the log of commits in between them is not).

So anybody who thinks that 'diff' and 'log' have *anything* to do with each other is fundamentally confused. Not just about git, btw. It's true in any model - it's fundamental.

As to 'a...b', it also means somethign different for diff (two endpoints!) and log (set of commits). For diff, it means "show the difference between the common commit and 'b'", while for log it means "show all commits that are in either 'a' or 'b' but *not* in both".

So you should do
	# generate the diff from the common point
	git diff -p --stat a...b
	# show the commits that are in b but not in a
	git log a..b

where the difference between two dots and three dots is important, and stems directly from the fact that 'diff' and 'log' are two totally different operations that cannot _possibly_ have semantics that mean the same thing - because a "set of commits" is fundamentally different from "difference betwen two endpoints".

So both "a..b" and "a...b" have meaning for both diff and log, but which you want to use depends on what you are looking for.

They do have some relationship, of course. If you want to have a simple way to know which is which, then

 - "a..b" is a plain difference. Think of it as a subtraction. For "diff", 
   it is simply the diff between a and b, and for log it is the "set 
   difference" (shown as either just "-" or as "\" in set theory math) 
   between the commits that are in b and not in a.
 - "a...b" is a more complex difference. For log, it's no longer the 
   regular set difference, but a "symmetric difference" (usually shown as 
   a greek capital "Delta" in set theory math). And for "diff", it's no 
   longer just the diff between two states, it's the diff from a third 
   state (the nearest common state) to the second state.

In short: It's easy to think that "log" and "diff" are related, but they really are very fundamnetally different.

		Linus
Previous: Andrew MortonNext: Andrew Morton
Message 13 of 21 in “my git problem”
  1. Andrew MortonApr 27, 2008
  2. Linus TorvaldsApr 27, 2008
  3. Andrew MortonApr 27, 2008
  4. Linus TorvaldsApr 27, 2008
  5. Andrew MortonApr 28, 2008
  6. Johannes SchindelinApr 28, 2008
  7. Andrew MortonApr 28, 2008
  8. Johannes SchindelinApr 28, 2008
  9. Linus TorvaldsApr 28, 2008
  10. J. Bruce FieldsApr 29, 2008
  11. Jakub NarebskiApr 30, 2008
  12. Andrew MortonApr 28, 2008
  13. Linus TorvaldsApr 28, 2008
  14. Andrew MortonApr 28, 2008
  15. Carl WorthMay 1, 2008
  16. Daniel BarkalowApr 28, 2008
  17. Andrew MortonApr 28, 2008
  18. Linus TorvaldsApr 28, 2008
  19. Johannes SchindelinApr 28, 2008
  20. Linus TorvaldsApr 28, 2008
  21. Andrew MortonApr 29, 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.