sebastianbergmann/diff hiện có 7.6k sao trên GitHub, viết chủ yếu bằng PHP. Diff implementation
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/sebastianbergmann/diff là nguồn chính thức.
sebastianbergmann/diff có bao nhiêu sao?
sebastianbergmann/diff có 7.6k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/sebastianbergmann/diff. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
sebastianbergmann/diff có phải mã nguồn mở không?
Có — sebastianbergmann/diff phát hành theo license BSD-3-Clause, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/sebastianbergmann/diff.
sebastianbergmann/diff có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho sebastianbergmann/diff. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
sebastianbergmann/diff là gì?
sebastianbergmann/diff (sebastianbergmann/diff) là dự án PHP trên GitHub. Theo mô tả gốc: Diff implementation
Đọc đầy đủ README ở tab phía trên.
diff có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về diff.