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

Re: make git diff output easier to read - use better diff heuristics

From
Jeff King <peff@peff.net>
Date
Feb 13, 2018, 16:08 UTC
Message-ID
<20180213160824.GA5203@sigill.intra.peff.net>
In-Reply-To
<CAOmC-AncOZfAwowXLjwDbL9Bdx1+=RbXsrd72LzEBd2W-=LAQg@mail.gmail.com>
On Tue, Feb 13, 2018 at 05:06:15PM +0200, Σπύρος Βαζαίος wrote:
Show 11 quoted lines
> Hi, I've came across an issue when using the git diff command. In
> particular the diff is different to what the svn diff produces. While
> both being correct the output of the svn diff is easier to understand
> than the git diff one. See the following issue on github where I
> initially reported the issue:
> 
> https://github.com/git-for-windows/git/issues/1494
> 
> I have Included a picture to better illustrate the problem. What do
> you think? Is it possible to make git diff output similar to svn diff
> regarding this issue?

Try "git diff --no-indent-heuristic", which makes your example look better. Here's a quick reproduction:

-- >8 --
cat >foo.c <<\EOF
static struct foo bar[] = {
#ifdef SOMETHING
	{ "stats.info", MNU_GBX_FSTAINF, etc },
	{ "expired.info", MNU_GBX_FSTAINF, etc },
	{ "info.log", MNU_GBX_INFOLOG, etc },
#endif
	{ NULL, 0, 0 },
};
EOF
sed '6a\
#ifdef WITH_EMU\
	{ "SoftCam.Key", MNU_CFG_FSOFTCAMKEY, etc },\
#endif
' <foo.c >bar.c
-- 8< --
Now this looks ugly:
  git diff --no-index foo.c bar.c
but this does not:
  git diff --no-index --no-indent-heuristic foo.c bar.c

That heuristic is described in 433860f3d0 (diff: improve positioning of add/delete blocks in diffs, 2016-09-05). I'm not sure exactly why it does the wrong thing here, or if it would be possible to tweak the weighting factors to make it work.

-Peff
Previous: Σπύρος ΒαζαίοςNext: Stefan Beller
Message 2 of 5 in “make git diff output easier to read - use better diff heuristics”
  1. Σπύρος ΒαζαίοςFeb 13, 2018
  2. Jeff KingFeb 13, 2018
  3. Stefan BellerFeb 13, 2018
  4. Σπύρος ΒαζαίοςFeb 13, 2018
  5. Michael HaggertyFeb 13, 2018

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.