Stax
Tools

Diff Checker

Compare two texts line by line and see exactly what changed.

+4 added3 removed4 unchanged
ORIGINAL
MODIFIED
DIFF RESULT
- function greet(name) {
- console.log("Hello, " + name);
- return name;
+ function greet(name, greeting = "Hello") {
+ console.log(greeting + ", " + name + "!");
}
const user = "Alice";
+ const admin = "Bob";
greet(user);
+ greet(admin, "Hi");

Text diff — อะไรเปลี่ยนแปลงไป?

การใช้งานทั่วไป

LCS diff ทำงานอย่างไร

การรู้ว่าอะไรเปลี่ยนแปลงไประหว่างเอกสารหรือไฟล์โค้ดสองเวอร์ชันเป็นหนึ่งในงานที่พบบ่อยที่สุดในการพัฒนาซอฟต์แวร์และงานด้านเนื้อหา เครื่องมือ diff แสดงชุดการเปลี่ยนแปลงขั้นต่ำที่จำเป็นในการเปลี่ยนจากต้นฉบับไปเป็นเวอร์ชันที่แก้ไข

อัลกอริทึม Longest Common Subsequence ค้นหาชุดบรรทัดที่ใหญ่ที่สุดที่ปรากฏในทั้งสองข้อความในลำดับเดียวกัน (แต่ไม่จำเป็นต้องต่อเนื่อง) บรรทัดในชุด common นี้คือ "ไม่เปลี่ยนแปลง" ทุกอย่างที่เหลือถูก add (มีเฉพาะใน modified) หรือ remove (มีเฉพาะใน original) นี่คืออัลกอริทึมพื้นฐานเดียวกับที่ git, diff และระบบ version control ส่วนใหญ่ใช้

นักพัฒนาที่ไม่มี IDE บนเครื่อง (เรียกดูจากโทรศัพท์ หรืออยู่ในเครื่องของลูกค้า) วาง code snippet สองชิ้นเพื่อค้นหาความแตกต่างอย่างรวดเร็ว นักเขียนเปรียบเทียบร่างบทความหรืออีเมลสองฉบับเพื่อดูว่า editor เปลี่ยนอะไร ทีมกฎหมายเปรียบเทียบการแก้ไขสัญญาทีละข้อโดยไม่ต้องติดตั้งซอฟต์แวร์พิเศษ วิศวกร DevOps วาง nginx หรือไฟล์ JSON config จากสองสภาพแวดล้อมเพื่อระบุแหล่งของความคลาดเคลื่อน ทีม support เปรียบเทียบ log snippet ที่ลูกค้าส่งมากับ output ที่คาดหวังเพื่อวินิจฉัยปัญหา

เครื่องมือนี้เหมาะที่สุดสำหรับการเปรียบเทียบแบบ ad-hoc ด่วนของ text snippet, ไฟล์ config หรือ code block สั้นๆ ที่คุณไม่ต้องการประวัติเวอร์ชันหรือการติดตามไฟล์ สำหรับการพัฒนาโค้ดอย่างต่อเนื่อง git diff คือตัวเลือกที่ถูกต้อง — มันรวมเข้ากับ version control, รองรับการเปรียบเทียบ staged กับ unstaged และสามารถ diff ต้นไม้ไฟล์ทั้งหมดได้ ใช้ checker นี้เมื่อคุณมีข้อความสองชิ้นและเพียงต้องการเห็นสิ่งที่เปลี่ยนแปลงโดยไม่มีการตั้งค่าใดๆ

Trailing space และบรรทัดว่างอาจทำให้ diff เข้าใจผิดได้ — บรรทัดที่ดูเหมือนกันอาจแสดงว่าเปลี่ยนแปลงเพราะ trailing space ที่มองไม่เห็น ถ้าคุณกำลังเปรียบเทียบโค้ด ให้ลบ trailing whitespace ใน editor ก่อนวาง สำหรับไฟล์ขนาดใหญ่เกิน 300 บรรทัด อัลกอริทึม LCS จะลดระดับลงเป็น view แบบ full-swap ที่เรียบง่ายกว่า; แบ่งไฟล์เป็นส่วนๆ และเปรียบเทียบแต่ละส่วนแยกกันเพื่อ diff ที่ละเอียด

  • Code review — ตรวจสอบสิ่งที่เปลี่ยนแปลงในไฟล์ก่อน commit
  • ไฟล์ config — ค้นหาความแตกต่างระหว่าง config ของ production และ staging
  • กฎหมาย/สัญญา — เปรียบเทียบสองเวอร์ชันของข้อตกลง
  • การแก้ไขเนื้อหา — ติดตามสิ่งที่ editor เปลี่ยนแปลงในร่างของคุณ
  • การ debug — เปรียบเทียบเวอร์ชันที่ทำงานได้กับเวอร์ชันที่เสียของ config หรือ snippet

คำถามที่พบบ่อย

How does the diff checker work?
The tool uses the Longest Common Subsequence (LCS) algorithm to find lines that appear in both texts. Lines only in the original are shown in red (removed), lines only in the modified are shown in green (added), and common lines are shown without highlighting.
What can I use this for?
Comparing versions of code, configuration files, documents, or any text. It's useful for reviewing changes before committing to version control, comparing contract revisions, checking what changed between two versions of a file, or spotting differences in two similar text blocks.
Is there a character or line limit?
The LCS algorithm is limited to 300 lines per side for performance. For texts longer than this, a simplified fallback is used showing all original lines as removed and all modified lines as added. For large file diffs, use a dedicated version control tool like git diff.
Does the diff work on word level or line level?
This tool performs line-by-line comparison. Each entire line is compared as a unit. This is the standard approach for code and document diffs — the same method used by git diff by default.
Is my text sent to a server?
No. All comparison happens entirely in your browser. No data is transmitted or stored.

เครื่องมือที่เกี่ยวข้อง