14 ms·
Difftastic, a structural diff tool that understands syntax
- vagab0nd 3y agoCan vimdiff take advantage of this?
- bloopernova 3y agoRelated, updating difftastic and friends if you installed via cargo: cargo install cargo-update cargo install-update --list cargo install-update --all Other fun Rust projects available via cargo: https://mise.jdx.dev/ https://mise.jdx.dev/ mise-en-place, a drop-in replacement for asdf https://asdf-vm.com/ https://asdf-vm.com/ that is really fast and flexible. https://github.com/ajeetdsouza/zoxide https://github.com/ajeetdsouza/zoxide is a fantastic cd replacement, which stores where you cd to, and you can then do a partial match like "z hel" might take you to "~/projects/helloworld". https://github.com/bootandy/dust https://github.com/bootandy/dust is a compliment to "du", shows which directories are using the most disk space.
- IshKebab 3y agoncdu is the best du replacement by far.
- polygamous_bat 3y agoI've always used dust as a replacement, and so I am curious to know if you have tried both tools: do you have thoughts on what makes ncdu better?
- IshKebab 3y agoDust is probably the best you can get without interactivity, so it's good for logs. But ncdu is a fully interactive file browser that lets you navigate through the tree, and crucially it lets you delete things without requiring a full rescan. It's amazing for freeing up disk space by deleting things you don't need anymore, which is probably 95% of the reasons I run `du`.
- kstrauser 3y agoI love zoxide! Also for your list: lsd, a prettier ls.
- bloopernova 3y agoso... many... colours! Looks great, thank you for the recommendation.
- qmmmur 3y agoWow, I installed mise-en-place. It's exactly what I wanted asdf to be.
- bloopernova 3y agoIt's so much faster than asdf, the dev did a really great job.
- drewbitt 3y agoThe rename to mise broke my workflow for a bit and the library is changing fast & adding new features frequently. That's good, but I hope it can stabilize a bit, so things don't get deprecated again. Still love it.
- bloopernova 3y agoYeah, the name "rtx" was not easy to search for. Mise is a much nicer name too. I am currently using it with direnv, but there's enough functionality in mise to replace that too. I keep meaning to spend some time making mise work without direnv, but it's not been urgent since everything pretty much just works now. I like the active development since the dev really seems to care about doing a great job, and I've been lucky enough so far that my (simple) workflows haven't been impacted.
- prh8 3y agoDo you know if there’s a way to do per directory aliases with Mise? Every time I see a tool for directory environment, that’s the one feature in really hoping for
- bloopernova 3y agodirenv + mise does exactly that. When I cd to various directories I get different env vars, it's pretty neat. Setting aliases would just be a case of adding them. https://github.com/jdx/mise/discussions/1525 https://github.com/jdx/mise/discussions/1525 for an example of how I use direnv with mise. https://mise.jdx.dev/direnv.html https://mise.jdx.dev/direnv.html https://mise.jdx.dev/templates.html https://mise.jdx.dev/templates.html
- arlort 3y agoAnother three very neat ones are - https://github.com/eza-community/eza https://github.com/eza-community/eza (ls with some added visual sugar) - https://github.com/ClementTsang/bottom https://github.com/ClementTsang/bottom (htop but with graphs) - https://github.com/sharkdp/bat https://github.com/sharkdp/bat (cat with syntax highlight)
- satvikpendem 3y agoAlso, cargo-binstall (cargo binary install) which allows you to not have to compile every single time you cargo install and instead allows you to just install the binaries for a specific program. It also integrates with cargo install-update.
- bloopernova 3y agoI originally tried binstall but it seemed to not work with our corporate proxy. However, I decided to give it another go after seeing your comment. Now, it works great! I tried it with a mise update, and it pulled down the right binary with no proxy problems. Thank you for the reminder and recommendation, much appreciated!!
- satvikpendem 3y agoNice to see it works for you, I like the crate as well for my utility cargo installations.
- tomatao 3y agoHow do these compare to https://github.com/moonrepo/proto https://github.com/moonrepo/proto ?
- bloopernova 3y agoI haven't used proto so unfortunately I can't answer your question, sorry about that.
- letmeinhere 3y agoMy favorite of the new `du`s is dua-cli, an ncdu clone (an interactive TUI). I went hunting because the latter didn't have a light-mode.
- sanity 3y agoInteresting, I found Semantic Merge [1] years ago but it was never open source. This just does diff but not merge, but at least it's open source - and the diffs look a lot nicer, I've already made it my default. Any plans to extend it to merging? [1] https://docs.plasticscm.com/semanticmerge https://docs.plasticscm.com/semanticmerge
- rideontime 3y agoWas going to suggest this myself, this was a godsend when I was working with a big team on a C# project going through a messy refactor.
- OJFord 3y ago> Any plans to extend it to merging? The GitHub readme: > Can difftastic do merges? > No. AST merging is a hard problem that difftastic does not address. > AST diffing is a also lossy process from the perspective of a text diff. Difftastic will ignore whitespace that isn't syntactically significant, but merging requires tracking whitespace.
- mlavrent 3y agoI’m almost not sure why tools like git don’t ship with this as default. Been using difft for about a year now, and my main complaint is that it makes it hard to go back and use other diff tools when I don’t have difft available :). I am curious if there’s been any work on _semantic_ diff tools as well (for when eg the syntax changes but the meaning is the same). It seems like an intractable problem in the general but maybe it’s doable and/or useful for smaller DSLs or subsets of some languages?
- ruined 3y ago>I am curious if there’s been any work on _semantic_ diff tools as well (for when eg the syntax changes but the meaning is the same). if you do this your difftool becomes a compiler
- hobs 3y agoThat's exactly what I have done with diffing SQL in lazy mode - just use a server and diff the AST/plan.
- slotrans 3y agoTwo semantically equivalent SQL statements can plan differently...
- rrrrrrrrrrrryan 3y agoThe exact same SQL statement can plan differently if table statistics change.
- hobs 3y agoAbsolutely and for this case a different plan mattered.
- mlavrent 3y agoSorry, I should've been clearer. I'm interested if there's any tool that does this kind of thing statically, without running the code. I guess a simple approach is to compile both programs and see if the generated code is the same, but I'd guess reasoning at the generated-code level will probably produce a lot more false positives (i.e. tool will report a change when there isn't one) than if you reason about the original program.
- pmayrgundter 3y ago"Do you know how to read @@ -5,6 +5,7 @@ syntax? Difftastic shows the actual line numbers from your files, both before and after." Preach! Just dropped it in and did a git diff.. works like a charm!
- neuromanser 3y ago> Do you know how to read @@ -5,6 +5,7 @@ syntax? Do you not?
- wffurr 3y agoNo, I sure don’t.
- pmayrgundter 3y ago20 years staring at it and no, i don't. i usually have to work it out from context. i think if you have vi or ed sensory organs it might work better for ya. which.. i still chuckle that vi is the visual editor, bc ed lol
- teaearlgraycold 3y agoNever needed to.
- snthpy 3y agoSame here. If there's a great ELI5 explanation somewhere, please post a link. Thanks
- NateEag 3y agoThe comma-separated number pairs are starting line number of hunk, and the number of lines in the hunk. The one starting with a minus sign is for the original file, the one with the plus prefix is for the new file. See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html https://www.gnu.org/software/diffutils/manual/html_node/Deta... for a canonical source and more detail
- 3y ago
- hrdwdmrbl 3y agoIt seems like a major lapse in product innovation that Github has not come out with something like this. They don't even have something to help you when the indentation changes, they usually just show it as a giant add & remove. Their diff viewer can and should be smarter.
- sroussey 3y agoGitHub has the option to ignore whitespace in a diff.
- mbork_pl 3y agoWhich is useful, but too crude.
- neuromanser 3y agoGithub can't even recognize syntax, let alone provide semantic diffs! In fact, Github can't even tell that foo.cpp.in is different from foo.mk.in! Any foo.t is declared to be Perl, with no way to fix it…There are a decade-old tickets!
- bPspGiJT8Y 3y agoTree-sitter optimizes for performance (to use in editors), not for correctness. In fact even TS' core developers advocate for not bothering too much with correctness of grammars[1]. I imagine this constraint would be a deal-breaker for GitHub or anyone else in their position. [1] https://github.com/tree-sitter/tree-sitter/issues/130#issuecomment-364830185 https://github.com/tree-sitter/tree-sitter/issues/130#issuec...
- asicsp 3y agoPrevious discussions: https://news.ycombinator.com/item?id=27768861 https://news.ycombinator.com/item?id=27768861 (297 points | 3 years ago | 61 comments) https://news.ycombinator.com/item?id=32746258 https://news.ycombinator.com/item?id=32746258 (698 points | 2 years ago | 90 comments) https://news.ycombinator.com/item?id=30841244 https://news.ycombinator.com/item?id=30841244 (983 points | 2 years ago | 219 comments)
- zokier 3y agoThere is also gumtree that does ast based diffing https://github.com/GumTreeDiff/gumtree https://github.com/GumTreeDiff/gumtree
- kstrauser 3y agoFor those who don't already know, this is built on tree-sitter (https://tree-sitter.github.io/tree-sitter/ https://tree-sitter.github.io/tree-sitter/) which does for parsing what LSP does for analysis. That is, it provides a standard interface for turning code into an AST and then making that AST available to clients like editors and diff tools. Instead of a neat tool like this having to support dozens of languages, it can just support tree-sitter and automatically work with anything that tree-sitter supports. And if you're developing a new language, you can create a tree-sitter parser for it, and now every tool that speaks tree-sitter knows how to support your language. Those 2 massive innovations are leading to an explosion of tooling improvements like this. Now every editor, diff tool, or whatever can support dozens or hundreds of languages without having to duplicate all the work of every other similar tool. That's freaking amazing.
- bfrog 3y agoWhile I agree tree-sitter is an amazing tool, writing the grammar out can be incredibly difficult I found. I tried writing out a grammar and highlighting query set for vhdl with tree-sitter, and found that there were a lot of difficulties in expressing vhdl grammar in tree-sitter.
- kstrauser 3y agoNo argument from me on that. The upside is that one person, somewhere, has to get it right one time and then we can all use it.
- grub5000 3y agoSeems like something LLMs should be useful for, if not now then soon enough
- HumanOstrich 3y agoI think many people are exhausted (at least I am) with the constant irrational exuberance of bolting AI onto every technology, product, and service in existence to end all of humanity's problems. It won't work like that.
- adamtaylor_13 3y agoDoes anyone know how to enable this for .html.erb files? I found it doesn't work properly in Ruby .erb files which makes it fallback to just regular ol diff behavior.
- coldbrewed 3y agoThat may require a tree-sitter implementation for erb templated html; it may exist but if so it's less of a mainstream thing. Some quick googling turns up https://github.com/tree-sitter/tree-sitter-embedded-template https://github.com/tree-sitter/tree-sitter-embedded-template which may or may not meet your needs.
- mihaigalos 3y agoNice tool. Also relevant: https://github.com/dandavison/delta https://github.com/dandavison/delta
- adamc 3y agoDoesn't seem to have a Debian install.
- Night_Thastus 3y agoNo MSYS install, sadly. :(
- quasarj 3y agoIt's just a cargo package. Is there a working rust/cargo toolchain under MSYS?
- Night_Thastus 3y agoYes, there is one here: https://packages.msys2.org/base/mingw-w64-rust https://packages.msys2.org/base/mingw-w64-rust Looks like it wasn't all that hard. Honestly the harder part is getting my shell to remember the changes to PATH.
- mnw21cam 3y agoNo package for Debian-like systems yet.
- chalst 3y agoYou can be the one to create such a package…
- aus10d 3y agoReally cool idea!
- airstrike 3y agoFantastic tool. Now we just need the vscode extension ;-)
- modernerd 3y agoSemanticDiff is probably the closest for now, although I don't think it uses tree-sitter. https://semanticdiff.com/ https://semanticdiff.com/ Found via https://github.com/Wilfred/difftastic/issues/194 https://github.com/Wilfred/difftastic/issues/194.
- pjturpeau 3y agoIt seems to be a great tool, however on the few checks I did on big XML files, it shows modified lines in normal green and modified attributes in bold green, which makes them difficult to detect visualy. I didn't find in the documentation how it is possible to change the style of the diff, or to ask for another color in the bold case. Any idea?
- jez 3y agoUnfortunately it doesn't appear to allow customizing colors yet. I chimed in on this issue[1] to express support for that. You may wish to also chime in on that one, or open a new issue if you think that the feature you're looking for is sufficiently different from the one discussed in that thread. [1]: https://github.com/Wilfred/difftastic/issues/611 https://github.com/Wilfred/difftastic/issues/611
- blackfawn 3y agoDifftastic seems really nice! Unfortunately it shows some changed binary files which makes it sort of unusable. `file` reports these files as "ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped" and the MIME type/encoding is "application/x-sharedlib; charset=binary" so not sure why difftastic is trying to show them as thousands of changed lines of text...
- nibab 3y agoThis is great! I wish my PR review tools allowed me to plug in something like this. Hopefully one day we will go back to the world of customizable/plugin-based software. Most of my web tools are very prescriptive about the user experience and dont let me tailor my tools.
- sanxchit 3y agoWhat an amazing tool, wish it had a GUI version as well.
- layer8 3y agoFrom the screenshot examples in the readme, I’m not sure how substantial the benefits are over GUI tools like Kdiff3 or WinMerge that have existed for ages.
- sanxchit 3y agoI've used WinMerge, its very different from the above tool because its still a text diff. It often gets the diffs wrong when multiple lines are involved. Take this trivial C# example: https://www.diffchecker.com/gr0H7qA1/ https://www.diffchecker.com/gr0H7qA1/ Most diff tools throw out something that is quite difficult to parse, but difftastic gave me the most concise diff so far.
- abledon 3y agoonnly found out about this because it was an option to view diffs when installing git using Nix
- keybored 3y agoI think I use this indirectly through the git-delta pager which is a great pager replacement for git.
- Aissen 3y agoNo, I don't think delta integrates with difftastic: https://github.com/dandavison/delta/issues/535 https://github.com/dandavison/delta/issues/535
- akkartik 3y agoIs there a way to make the output more familiar to diff users? I've turned on --inline. I also mostly don't care enough about line numbers to want them on every line, so prefer the '<' and '>' leaders. Also, on Arch there doesn't seem to be a man page.
- xyzelement 3y agoI don't write enough code / write it professionally anymore to integrate it into my life BUT MAN this is a great idea. In general, we're overflowing in TMI which makes it hard to suss out what matters. For example at work I often read docs that describe what we do for customer X vs customer Y and it takes a ton of work to suss out the 1% of text that is different between those two, which is really what you want to understand and validate. So anything that makes just the impactful change stand out is beyond welcome.
- jmholla 3y agoI tried switching to this, but I found it noisy and use weird formatting for things that didn't change. I went back to using icdiff[0]. [0]: https://github.com/jeffkaufman/icdiff https://github.com/jeffkaufman/icdiff
- markrages 3y agoDoes the output work with patch(1)? Or does this use a different patch?
- drcongo 3y agoI love this so much. I hate reading cli diffs, but this is instantly understandable.
- throwawaygo 3y agoHow long until this is just a prompt?
- brainzap 3y agofuck yeah finally, I am so sick of text based diff
- chalst 3y agoDifftastic is text-based.
- Arrgh 3y agoLong, long ago, I used a library called Augeas (https://augeas.net/ https://augeas.net/) in a drift-detection product*, so that if we detected a difference in config files, either on the same server through time, or on different servers that were supposed to be similar, we could de-noise the diffs, and more importantly, let users write fine-grained, but syntax-tolerant, allow-lists like "this particular setting is allowed to differ"... or even "this particular setting can have one of the following list of values". :) * the company was acquired by Splunk years after we shelved that product
- dsp_person 3y agoInteresting that while the arch linux the package weighs in a 7MB, it extracts to 80MB installed, and the `difft` binary is a whole 78MB. On a ZFS dataset with LZ4 compression du says it's 17MB. I wonder why not just compress whatever is so compressible in the binary? It would probably even load faster to decompress it in ram.
- speed_spread 3y agoIts probably related to the comment here about the Nim parser being an unmergable 60mb C file. It looks like TreeSitter requires lots and lots of code, a lot of which must be redundant / compressible.
- frankjr 3y agoJust a data point because you mentioned compression and I got curious - it's about 10MB on btrfs with zstd:1. Processed 1 file, 614 regular extents (614 refs), 0 inline. Type Perc Disk Usage Uncompressed Referenced TOTAL 14% 10M 77M 77M none 100% 1.1M 1.1M 1.1M zstd 12% 9.8M 76M 76M
- dsp_person 3y agoApparently ZFS 2.2.0 added an early abort capability for zstd compression. Maybe I'll switch over to it.
- dark-star 3y ago> It would probably even load faster to decompress it in ram. An executable is not loaded into RAM completely and then started. It's memory mapped and only the parts that actually get used are loaded (when they are needed). This is why large binaries get slower when you compress them, because then the demand-paging doesn't work anymore I did the test with a 280mb Windows EXE some years ago, compressed down to like 70 megs or so but took multiple seconds longer to start up than the original For some scenarios might make sense (running binaries across the network maybe) but in most cases an uncompressed binary will start up faster
- nialv7 3y agoDifftastic is great, but when I need to create patches I need to go back to good ol' diff... Is there a patching tool that can apply difftastic diffs?
- replwoacause 3y agoI want for a nice diff tool on Mac that doesn’t cost an arm and a leg like Kaleidoscope. Right now I am using one called CompareMerge2 from the App Store which is pretty good.
- PlunderBunny 3y agoI too, settled on CompareMerge2 after casting around fruitlessly, and lusting after Kaleidoscope.
- catlan 3y agoHere a coupon code for 40% off: HN1337
- kstrauser 3y agoThanks for sharing that! I, too, have drooled over Kaleidoscope for ages. But I confess: at the discount rate it's still more expensive than my IDE (Nova). It has a million cool features that alas I don't need. I just want that gorgeous source code diffing, at a lower price point. (I don't expect you to say "great idea, sir, here's your coupon!". I'm sure you've done your analysis and you're at the price point that works best for you. I'm also not saying it's overpriced, just that it's more than I'm willing to pay for it given the functionality I want from it. This is just in the spirit of friendly user feedback.)
- vmladenov 3y agoKaleidoscope was fantastic before it turned into yet another subscription service :/
- yboris 3y agoRelated tool: diff2html also as a CLI - with one command opens a browser tab showing HTML diff (side by side or line by line) - a great way to review your work before committing. https://diff2html.xyz/ https://diff2html.xyz/
- ein0p 3y agoI wish someone would make a console 3 way merge with some rudimentary editing support. I know there’s vimdiff, but I just don’t gel with it. For the lack of a better description I just want a console version of Meld’s 3-pane merge.
- gexla 3y agoThanks for this. I'll give it a try. And for diffs in a different context, I really like Beyond Compare.
- domenkozar 3y agoIn devenv.sh: difftastic.enable = true;
- duncan_britt 3y agoCan it be made to work with magit in emacs?
- chalst 3y agoYes, since magit allows a call-out to diff and difftastic can be supplied as a binary, but magit allows you to use ediff, and Emacs allows use of tree-sitter, so I don’t really see the point.
- arcastroe 3y agoCould this be integrated with something like Gitea or is this purely for CLI based use?
- jerrygoyal 3y agohow to set it up as the default git diff in vscode?
- trashymctrash 3y agoIf you are curious, here is how you can integrate it into a Jetbrains IDE: https://glyphy.com/a/2022/structural-diff-with-difftastic-and-jetbrains-ides/ https://glyphy.com/a/2022/structural-diff-with-difftastic-an... I tried it, but unfortunately it's not as seamless as it could be, so I reverted back to Jetbrain's native diffing, which is quite good anyway.
- mtmk 3y agoI'm really pleased to hear about this and looking forward to the updates in my daily tooling. I feel like for decades I haven't seen a fundamental improvement in diff/merge tooling. It will finally be great to not parse the change in my head. For example, one diff problem I keep noticing has been the curly brace shift when you add a new function or a block. Even if it can only identify those, that would be a win for me.
- alkonaut 3y agoIs there a way to tell difft that a particular extension is a particular format? Or that it could guess for unknown formats whether they are xml by e.g. scanning the first lines for <tags> before falling back to text? Because xml files are very often not using the extension xml and treating them as plaintext means losing a lot of the structural goodness.
- planetpluta 3y agoYes there is an `—-override` option you can use to specify the language in which a file should be parsed. https://github.com/Wilfred/difftastic/blob/master/CHANGELOG.md#language-detection https://github.com/Wilfred/difftastic/blob/master/CHANGELOG....
- alkonaut 3y agoPerfect, thanks.
- rutchkiwi 3y agoLooks cool, but I'm confused about what the different colors mean. What is purple/blue? (green and red is easy to understand)
- tln 3y agoWow, this looks great. Get that man some more Emacs and coffee!
- amai 3y agoIf you are in need of a diff tool for jupter notebooks use https://www.reviewnb.com/ https://www.reviewnb.com/ and for word documents use https://www.simuldocs.com/ https://www.simuldocs.com/
- zikohh 3y agoDelta is a drop in replacement with git diffs. Why is this not possible with difftastic? I.e it suggests to create aliases etc https://github.com/dandavison/delta https://github.com/dandavison/delta
- zimmund 3y agoThe diff itself is impressive, but in terms of styling I still prefer diff-so-fancy[1]. It's easier to read at a glance. [1]: https://github.com/so-fancy/diff-so-fancy/ https://github.com/so-fancy/diff-so-fancy/
- chalst 3y agoEmacs has a git client, Magit, which can use ediff, the Elisp implementation of diff. Since Emacs is widely used for parsing, and can parse using tree-sitter, Emacs doesn’t seem to benefit from difftastic. But perhaps I’m overlooking some capability of difftastic.