TopGit tracks sebastianbergmann/diff on GitHub. The project has 7.6k stars. Diff implementation
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Diff implementation for PHP, factored out of PHPUnit into a stand-alone component.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
composer require sebastian/diff
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev sebastian/diff
Usage
Generating diff
The Differ class can be used to generate a textual representation of the difference between two strings:
<?php declare(strict_types=1);
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
$differ = new Differ(new UnifiedDiffOutputBuilder);
print $differ->diff('foo', 'bar');
The code above yields the output below:
--- Original
+++ New
@@ @@
-foo
+bar
The UnifiedDiffOutputBuilder used in the example above generates output in "unified diff"
format and is used by PHPUnit, for example.
The StrictUnifiedDiffOutputBuilder generates output in "strict unified diff" format with
hunks, similar to diff -u and compatible with patch or git apply.
The DiffOnlyOutputBuilder generates output that only contains the lines that differ.
If none of these three output builders match your use case then you can implement
DiffOutputBuilderInterface to generate custom output.
Parsing diff
The Parser class can be used to parse a unified diff into an object graph:
use SebastianBergmann\Diff\Parser;
use SebastianBergmann\Git;
$git = new Git('/usr/local/src/money');
$diff = $git->getDiff(
'948a1a07768d8edd10dcefa8315c1cbeffb31833',
'c07a373d2399f3e686234c4f7f088d635eb9641b'
);
$parser = new Parser;
print_r($parser->parse($diff));
Note: If the chunk size is 0 lines, i.e., getStartRange() or getEndRange() return 0, the number of line returned by getStart() or getEnd() is one lower than one would expect. It is the line number after which the chunk should be inserted or deleted; in all other cases, it gives the first line number of the replaced range of lines.
Does sebastianbergmann/diff have a project website?
No homepage URL was recorded for sebastianbergmann/diff in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How many stars does sebastianbergmann/diff have?
sebastianbergmann/diff has 7.6k GitHub stars — refresh the page for the live number, or check github.com/sebastianbergmann/diff. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is sebastianbergmann/diff open source?
Yes — sebastianbergmann/diff ships under the BSD-3-Clause license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/sebastianbergmann/diff.
What is sebastianbergmann/diff?
sebastianbergmann/diff (sebastianbergmann/diff) is a PHP project on GitHub. From the project's own README: Diff implementation
Where do I read more about sebastianbergmann/diff?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/sebastianbergmann/diff is the definitive source.
Read full README in the tab above.
Is diff worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of diff.