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 27, 2008, 19:15 UTC
Message-ID
<alpine.LFD.1.10.0804271204510.3119@woody.linux-foundation.org>
In-Reply-To
<20080427112938.4dbe8e2a.akpm@linux-foundation.org>
On Sun, 27 Apr 2008, Andrew Morton wrote:
Show 8 quoted lines
> 
> Now, I want to generate a plain patch against mainline which will add the
> patches which are in git-ia64 and which aren't in mainline.  ie: when that
> patch is applied to mainline, we get git-ia64.  Sounds simple.
> 
> A naive
> 
> 	git-diff origin git-ia64
Don't do that.

That will diff between the two branches, and if they both contain stuff (which they obviously do), you'll get all the things that are in origin (but not git-ia64) as a reversed diff.

What you _want_ is the diff from the last common point, aka the "merge base".

With git, you could do that as
	merge_base=$(git merge-base origin git-ia64)
	git diff $merge_base git-ia64

but there is a convenient shorthand for that, which is to use "a...b" (three dots!), so

	git diff -p --stat origin...git-ia64
should generally get you what you want.

I say *generally*, because there might be multiple merge-bases if there are crossing merges between the two branches and there is no well-defined single common point. But that criss-cross case almost never happens for the kernel, because I've been pretty good at trying to teach maintainers to not generate that kind of complex history (it doesn't just obfuscate the above kind of situation, it also makes gitk output harder-to-read than it otherwise would be).

That said, your script (that does a merge) should have been able to get the diff too, and in fact handle even the criss-cross case. It's written a bit strangely (like having that really old-fashioned way of using git merge, passing in HEAD explicitly etc).

			Linus
Previous: Andrew MortonNext: Andrew Morton
Message 2 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.