difftastic

a structural diff that understands syntax πŸŸ₯🟩

https://github.com/wilfred/difftastic

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • βœ“
    CITATION.cff file
    Found CITATION.cff file
  • βœ“
    codemeta.json file
    Found codemeta.json file
  • βœ“
    .zenodo.json file
    Found .zenodo.json file
  • β—‹
    DOI references
  • β—‹
    Academic publication links
  • βœ“
    Committers with academic emails
    7 of 440 committers (1.6%) from academic institutions
  • β—‹
    Institutional organization owner
  • β—‹
    JOSS paper metadata
  • β—‹
    Scientific vocabulary similarity
    Low similarity (12.2%) to scientific vocabulary

Keywords

diff tree-sitter

Keywords from Contributors

argument-parser command-line-parser parsed-arguments positional-arguments subcommands distributed transformer interpretability init services
Last synced: 6 months ago · JSON representation ·

Repository

a structural diff that understands syntax πŸŸ₯🟩

Basic Info
Statistics
  • Stars: 22,854
  • Watchers: 62
  • Forks: 394
  • Open Issues: 241
  • Releases: 47
Topics
diff tree-sitter
Created about 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Citation

README.md

it's difftastic!
English manual Chinese manual crates.io codecov.io

Difftastic is a structural diff tool that compares files based on their syntax.

For installation instructions, see Installation in the manual.

Basic Example

Screenshot of difftastic and JS

In this JavaScript example, we can see:

(1) Difftastic understands nesting. It highlights the matching { and }, but understands that foo() hasn't changed despite the leading whitespace.

(2) Difftastic understands which lines should be aligned. It's aligned bar(1) on the left with bar(2) on the right, even though the textual content isn't identical.

(3) Difftastic understands that line-wrapping isn't meaningful. "eric" is now on a new line, but it hasn't changed.

One Minute Demo

asciicast

This one minute screencast demonstrates difftastic usage with both standalone files and git.

Languages

Difftastic supports over 30 programming languages, see the manual for the full list.

If a file has an unrecognised extension, difftastic uses a textual diff with word highlighting.

Known Issues

Performance. Difftastic scales relatively poorly on files with a large number of changes, and can use a lot of memory.

Display. Difftastic has a side-by-side display which usually works well, but can be confusing.

Robustness. Difftastic regularly has releases that fix crashes.

Non-goals

Patching. Difftastic output is intended for human consumption, and it does not generate patches that you can apply later. Use diff if you need a patch.

(Patch files are also line-oriented, which is too limited for difftastic. Difftastic might find additions and removals on the same line, and it tracks the relationship between line numbers in the old and new file.)

Merging. AST merging is a hard problem that difftastic does not address. You might be interested in the mergiraf tool ("merge giraffe"), which does do AST merging.

FAQ

Isn't this basically --word-diff --ignore-all-space?

Word diffing can't do this.

Difftastic parses your code. It understands when whitespace matters, such as inside string literals or languages like Python. It understands that x-1 is three tokens in JS but one token in Lisp.

Can I use difftastic with git?

You can! The difftastic manual includes instructions for git usage. You can also use it with mercurial.

If you're an Emacs user, check out this blog post showing one way to use difftastic with magit, as well as difftastic.el.

Does difftastic integrate with my favourite tool?

Probably not. Difftastic is young. Consider writing a plugin for your favourite tool, and I will link it in the README!

What about parse errors?

By default, difftastic falls back to a line-oriented diff whenever parse errors are encountered.

This is a conservative choice to ensure that difftastic never claims two syntactically different files are the same.

Parse errors can occur if the file uses language features that the parser does not understand, if the language relies on a preprocessor before parsing (e.g. C++), or if the file has genuine syntactic mistakes.

In practice, difftastic virtually always produces a good result when there are a few minor parse errors. Consider allowing a small number of parse errors when using difftastic.

$ export DFT_PARSE_ERROR_LIMIT=20 $ difft foo1.c foo2.c

Can difftastic help me with merge conflicts?

Yes! As of version 0.50, difftastic understands merge conflict markers (i.e. <<<<<<<, ======= and >>>>>>>).

Pass your file with conflicts as a single argument to difftastic. Difftastic will construct the two conflicting files and diff those.

$ difft file_with_conflicts.js

Can difftastic do merges?

No. AST merging is a hard problem that difftastic does not address.

AST diffing is a lossy process from the perspective of a text diff. Difftastic will ignore whitespace that isn't syntactically significant, but merging requires tracking whitespace.

The mergiraf tool does offer merges based on a tree-sitter AST however.

Can difftastic ignore reordering?

No. Difftastic always considers order to be important, so diffing e.g. set(1, 2) and set(2, 1) will show changes.

If you're diffing JSON, consider sorting the keys before passing them to difftastic.

$ difft <(jq --sort-keys < file_1.json) <(jq --sort-keys < file_2.json)

See also Tricky Cases: Unordered Data Types in the manual.

Can I use difftastic to check for syntactic changes without diffing?

Yes. Difftastic can check if the two files have the same AST, without calculating a diff. This is much faster than normal diffing, and useful for building tools that check for changes.

For example:

$ difft --check-only --exit-code before.js after.js

This will set the exit code to 0 if there are no syntactic changes, or 1 if there are changes found.

Why aren't colours appearing in my terminal?

Difftastic uses ANSI bright colours by default, but some terminal themes show bright colours as grey. Solarized is a popular theme that does this.

If you're a Solarized user, use export DFT_BACKGROUND=light to disable bright colours, or try a different terminal colour scheme.

How does it work?

Difftastic treats structural diffing as a graph problem, and uses Dijkstra's algorithm.

My blog post describes the design, and there is also an internals section in the manual.

Translation

License

Difftastic is open source under the MIT license, see LICENSE for more details.

This repository also includes tree-sitter parsers by other authors in the vendored_parsers/ directory. These are a mix of the MIT license and the Apache license. See vendored_parsers/*/LICENSE for more details.

Files in sample_files/ are also under the MIT license unless stated otherwise in their header.

Owner

  • Name: Wilfred Hughes
  • Login: Wilfred
  • Kind: user
  • Location: Bay Area, USA

PL enthusiast, Emacs addict, and an advocate for human factors.

Citation (CITATION.cff)

cff-version: 1.2.0
title: Difftastic
message: 'To cite difftastic in publications use:'
type: software
authors:
  - given-names: Wilfred
    family-names: Hughes
    email: me@wilfred.me.uk
url: https://github.com/wilfred/difftastic
repository-artifact: https://crates.io/crates/difftastic
abstract: A syntactic diffing tool
keywords:
  - diffing
  - programming languages
license: MIT

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 13,844
  • Total Committers: 440
  • Avg Commits per committer: 31.464
  • Development Distribution Score (DDS): 0.796
Past Year
  • Commits: 248
  • Committers: 23
  • Avg Commits per committer: 10.783
  • Development Distribution Score (DDS): 0.246
Top Committers
Name Email Commits
Wilfred Hughes me@w****k 2,819
Max Brunsfeld m****d@g****m 2,151
Rick Winfrey r****y@g****m 984
Amaan Qureshi a****2@g****m 494
joshvera j****h@j****m 447
Timothy Clem t****m@g****m 343
Rob Rix r****x@g****m 289
Kolja Lampe r****e@g****m 279
Damien Guard d****g@g****m 237
Joran Honig j****g@g****m 199
Anantha Kumaran a****n@g****m 183
Antonio de Jesus Ochoa Solano a****o@g****m 177
ganezdragon g****3@g****m 169
6cdh c****h@g****m 161
sogaiu 9****2 159
Nikolaj Sidorenco n****6@h****m 150
fwcd f****l@g****m 150
Ayman Nadeem a****m@g****m 149
Alexandre Muller m****r@o****m 148
Alex Pinkus a****s@g****m 131
Yuya Nishihara y****a@t****g 125
mhoffm m****m@p****e 120
Uy Ha h****y@g****m 111
Maksim Novikov m****k@g****m 110
Azganoth i****r@g****m 109
Torsten Schmits t****s@g****m 108
Patrick FΓΆrster p****r 104
Eugene Yokota e****n@g****m 97
Stephan Seitz s****z@f****e 93
Jonathan Arnett j****0@g****m 88
and 410 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 344
  • Total pull requests: 142
  • Average time to close issues: 3 months
  • Average time to close pull requests: about 2 months
  • Total issue authors: 221
  • Total pull request authors: 94
  • Average comments per issue: 1.92
  • Average comments per pull request: 2.25
  • Merged pull requests: 68
  • Bot issues: 0
  • Bot pull requests: 7
Past Year
  • Issues: 75
  • Pull requests: 37
  • Average time to close issues: 20 days
  • Average time to close pull requests: 16 days
  • Issue authors: 57
  • Pull request authors: 23
  • Average comments per issue: 0.65
  • Average comments per pull request: 1.19
  • Merged pull requests: 18
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Wilfred (93)
  • berrymot (4)
  • tomwhoiscontrary (4)
  • gthb (3)
  • mattpass (3)
  • bradzacher (3)
  • frontsideair (2)
  • tmysik (2)
  • iacore (2)
  • Freaksed (2)
  • Krinkle (2)
  • arbrauns (2)
  • vi (2)
  • olivergondza (2)
  • nimrodkor (2)
Pull Request Authors
  • yuja (9)
  • arbrauns (7)
  • dependabot[bot] (7)
  • MarcelCoding (6)
  • nimrodkor (5)
  • yedayak (4)
  • Kissaki (4)
  • yusancky (4)
  • grunweg (4)
  • crbelaus (4)
  • Pi-Cla (4)
  • bryceberger (4)
  • sesse (3)
  • gthb (3)
  • egrieco (3)
Top Labels
Issue Labels
triaged (14) upstream-parser (8) help wanted (5) parse-error (4) feature-request (4) feature request (4) display (3) packaging (3) diffing (2) awaiting-response (2) bug (2) color (2) sliders (1) needs repro (1)
Pull Request Labels
dependencies (7)

Packages

  • Total packages: 5
  • Total downloads:
    • homebrew 867 last-month
    • cargo 162,264 total
  • Total docker downloads: 23,284,192
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 42
    (may contain duplicates)
  • Total versions: 117
  • Total maintainers: 2
proxy.golang.org: github.com/Wilfred/difftastic
  • Versions: 0
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.1%
Forks count: 1.7%
Average: 3.1%
Dependent packages count: 5.2%
Dependent repos count: 5.6%
Last synced: 6 months ago
proxy.golang.org: github.com/wilfred/difftastic
  • Versions: 0
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.1%
Forks count: 1.7%
Average: 3.1%
Dependent packages count: 5.2%
Dependent repos count: 5.6%
Last synced: 6 months ago
formulae.brew.sh: difftastic

Diff that understands syntax

  • Versions: 41
  • Dependent Packages: 0
  • Dependent Repositories: 42
  • Downloads: 867 Last month
Rankings
Stargazers count: 1.3%
Dependent repos count: 6.5%
Forks count: 10.4%
Average: 10.5%
Downloads: 14.7%
Dependent packages count: 19.4%
Last synced: 6 months ago
crates.io: difftastic

A structural diff that understands syntax.

  • Versions: 75
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 160,481 Total
  • Docker Downloads: 23,284,192
Rankings
Stargazers count: 0.7%
Docker downloads count: 2.1%
Forks count: 3.3%
Downloads: 9.3%
Average: 12.9%
Dependent repos count: 28.7%
Dependent packages count: 33.5%
Maintainers (1)
Last synced: 6 months ago
crates.io: difftastic-oc

A syntactic diff

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,783 Total
Rankings
Stargazers count: 0.6%
Forks count: 3.3%
Dependent repos count: 29.3%
Average: 31.8%
Dependent packages count: 33.8%
Downloads: 92.1%
Maintainers (1)
Last synced: 6 months ago