News for hackers. Stuff that matters.
Re:Unified versus Split Diff by knubie on Tuesday October 24, 2023 @03:23AM (#37995764)
A third (fourth?) option worth mentioning here is difftastic[0], which uses "structural" diffing (as opposed to line diffing) for more granular diff highlighting.

[0] https://github.com/Wilfred/difftastic

Re:Unified versus Split Diff by eviks on Tuesday October 24, 2023 @03:28AM (#37995797)
This is a great approach indeed, pity it's not integrated widely enough (think it only recently got a proper structured json output other tools could use)
Re:Unified versus Split Diff by m463 on Tuesday October 24, 2023 @04:34AM (#37996286)
ediff in emacs does this. Refine is what highlights the words that are different.
Re:Unified versus Split Diff by ParetoOptimal on Thursday October 26, 2023 @12:29AM (#38021606)
This blog post also details using difftastic within emacs and has neat comparisons:

https://shivjm.blog/better-magit-diffs/

Re:Unified versus Split Diff by videlov on Tuesday October 24, 2023 @05:19AM (#37996597)
Thank you for sharing this project! I have been searching for something like this for some time
Re:Unified versus Split Diff by grotorea on Tuesday October 24, 2023 @09:01AM (#37998586)
I also wonder if it's possible to go beyond this project and have git itself work on the syntax level instead of pure text.
Re:Unified versus Split Diff by ilyt on Tuesday October 24, 2023 @10:01AM (#37999298)
Git doesn't store diffs on logical level. Git operates on snapshots of trees. Commit is not "a collection of changes", it's a snapshot of a tree with attached predecessor of it.

Then the another layer (which can be git, but also can be any other tool, adding custom diff tool to git is very easy) uses that to generate diffs.

There is zero stopping anyone from adding contextual diffs to Git. Just ask it for content of both commits and feed it to the algorithm.

Yes, git underneath stores data as diffs but they are only vaguely related to logical structure of commits

Re:Unified versus Split Diff by grotorea on Tuesday October 24, 2023 @12:24PM (#38001439)
Interesting. Wonder if something like that can be used to make git cleverer about merges for example.
Re:Unified versus Split Diff by fanf2 on Tuesday October 24, 2023 @01:42PM (#38002561)
Git’s merge algorithm looks at three versions of the code: the two branch tips being merged, and their common ancestor. It might be better at resolving conflicts if it looked at some of the intermediate commits as well, but I don’t know of anything that does so.
Re:Unified versus Split Diff by ilyt on Tuesday October 24, 2023 @07:52PM (#38007353)
Merge part isn't pluggable like that IIRC. Would be interesting if that was given stable interface, then supposed "smart merge" tool could iterate with few ways to merge code while running tests to check which one produces least/no errors
Re:Unified versus Split Diff by yencabulator on Tuesday October 24, 2023 @06:29PM (#38006565)
> Yes, git underneath stores data as diffs but they are only vaguely related to logical structure of commits

And that's why we call that lower level compression trick "delta", not "diff".

Re:Unified versus Split Diff by Izkata on Tuesday October 24, 2023 @07:11PM (#38006972)
> Then the another layer (which can be git, but also can be any other tool, adding custom diff tool to git is very easy) uses that to generate diffs.

Linky: https://stackoverflow.com/questions/255202/how-do-i-view-git...

Re:Unified versus Split Diff by mechanicker on Tuesday October 24, 2023 @10:08AM (#37999371)
I feel it is best to leave git out of this - separation of concerns Let external tools evolve independently instead.
Re:Unified versus Split Diff by mi_lk on Tuesday October 24, 2023 @09:37AM (#37999003)
only side-by-side view, unfortunate for my unified view taste
Re:Unified versus Split Diff by nix0n on Tuesday October 24, 2023 @02:35PM (#38003316)
It has a --display=inline option now.
Re:Unified versus Split Diff by mi_lk on Tuesday October 24, 2023 @02:55PM (#38003578)
It works! Can't seem to find the option in GitHub README or the documentation though
Re:Unified versus Split Diff by mega_dean on Tuesday October 24, 2023 @11:32AM (#38000581)
A fourth (fifth?) option worth mentioning is patdiff: https://opensource.janestreet.com/patdiff/ From what I remember, it sometimes (35%) made diffs easier to read, usually (60%) made no difference, and rarely (5%) made them harder to read. I used it a few years ago though, so I don't remember specifically what the problem was. The only reason I stopped using it was because I started using magit for git diffs.
Re:Unified versus Split Diff by roryokane on Wednesday October 25, 2023 @12:11AM (#38009048)
I agree that the patience diff algorithm generally produces better results, but you don’t need the patdiff tool for that. You can configure Git’s own diffs to use patience: https://git-scm.com/docs/git-config#Documentation/git-config...

I see that patdiff also provides word-level diffing. You could instead get that feature with `git diff --word-diff` or Delta (https://github.com/dandavison/delta).

Re:Unified versus Split Diff by rmwaite on Tuesday October 24, 2023 @06:36PM (#38006632)
`git diff --word-diff` has something close to this and it’s really nice.