Live data from Hacker News

Better Git diff output for Ruby, Python, Elixir, Go

tekin.co.uk

11–20 of 53 posts

Re: Better Git diff output for Ruby, Python, Elixir, Go

#12
Diffs are still pretty bad at preserving context, especially the “greedy” diff algorithm that assumes that files are identical for as long as possible instead of preserving as much context around the change as possible (if the diff is equally large. This has the familiar effect where you add a method under an existing method and they both have the same documentation header prefix line such as /, then the diff will make a mess of it and not see your added method as a single chunk of text.

Instead of a regex per file type perhaps a better diff tool could actually diff the parsed code (if possible) and produce a more sensible diff and context?

Re: Better Git diff output for Ruby, Python, Elixir, Go

#13
post #8

I use delta as a diff tool: https://github.com/dandavison/delta It also offers contextual information as well as side-by-side diffs. For syntax highlighting, it uses the same as bat (the cat clone).

Insane that I never tried looking for different diff tools, thanks for the recommendation!

Re: Better Git diff output for Ruby, Python, Elixir, Go

#14
From the title I was hoping that it was going to do syntax-aware alignment of diffs, but alas no.

I've been using kdiff3 even though it hasn't been updated in a very long time because it has one killer feature: manual diff alignment. I can select a token in both (or all three) files and then force the diff to align at that point. It makes merges a whole lot easier. Sometimes, a single realign is all that's needed for a file merge to sort itself out. Even when that's not the case, it's easier to reason about the changes.

Did I miss something? That is, is that feature available in other diff/merge tools and I just haven't seen it?

Re: Better Git diff output for Ruby, Python, Elixir, Go

#15
post #14

From the title I was hoping that it was going to do syntax-aware alignment of diffs, but alas no. I've been using kdiff3 even though it hasn't been updated in a very long time because it has one killer feature: manual diff alignment. I can select a token in both (or all three) files and then force the diff to align at that point. It makes merges a whole lot easier. Sometimes, a single realign is all that's needed for…

> Did I miss something?

Sure

https://download.kde.org/stable/kdiff3/

Re: Better Git diff output for Ruby, Python, Elixir, Go

#16
post #14

From the title I was hoping that it was going to do syntax-aware alignment of diffs, but alas no. I've been using kdiff3 even though it hasn't been updated in a very long time because it has one killer feature: manual diff alignment. I can select a token in both (or all three) files and then force the diff to align at that point. It makes merges a whole lot easier. Sometimes, a single realign is all that's needed for…

Yeah me too. I actually had to go back and read the text to figure out what improvement had been made because it looked identical.

I was expecting something like MergeResolver which diffs Javascript ASTs:

https://mergeresolver.github.io/

Re: Better Git diff output for Ruby, Python, Elixir, Go

#18
post #14

From the title I was hoping that it was going to do syntax-aware alignment of diffs, but alas no. I've been using kdiff3 even though it hasn't been updated in a very long time because it has one killer feature: manual diff alignment. I can select a token in both (or all three) files and then force the diff to align at that point. It makes merges a whole lot easier. Sometimes, a single realign is all that's needed for…

Beyond Compare [0] has manual alignment. It works within files as well as within directories, allowing you to match up files with different names when comparing directories.

I don't think it has syntax-aware alignment, though.

[0]: https://www.scootersoftware.com/

Re: Better Git diff output for Ruby, Python, Elixir, Go

#19
post #9

Earlier quoted context omitted.

The header that indicates context. Default: @@ -24,7 +24,7 @@ class TicketPdf Configured: @@ -24,7 +24,7 @@ def tickets_as_html

Ah, thanks. I scanned those so many times but I never caught it. I think I'm used to not reading the header because, as this points out, it isn't always useful.

I use these a lot when someone sends a patch, I'll use `vim -t ` to jump to the definition of to better understand the change. (Where is from the header of the hunk.)

Re: Better Git diff output for Ruby, Python, Elixir, Go

#20
post #11

Is there a good utility for diff-ing JSON content? I am calling jq to sort keys first and then let the default textual diff highlight the changes, but that's neither convenient nor complete.

I've been doing similarly and have had pretty good success with that (https://www.jvt.me/posts/2020/08/24/pretty-print-json-diff/)
Post reply on HN