टेक्स्ट अंतर जाँचकर्ता

दो टेक्स्ट की तुलना करें और तुरंत अंतर खोजें।

आपका डेटा आपके डिवाइस से बाहर नहीं जाता

टेक्स्ट तुलना के बारे में

यह diff टूल दो टेक्स्ट की पंक्ति-दर-पंक्ति तुलना के लिए Longest Common Subsequence (LCS) एल्गोरिथम का उपयोग करता है। जोड़ हरे रंग में, हटाव लाल रंग में हाइलाइट होते हैं।

सामान्य उपयोग

अक्सर पूछे जाने वाले प्रश्न

क्या यह वर्ण-दर-वर्ण तुलना करता है?

यह टूल पंक्ति-दर-पंक्ति तुलना करता है। यदि एक पंक्ति में कोई भी परिवर्तन है (यहाँ तक कि एक भी वर्ण), तो पूरी पंक्ति को संशोधित के रूप में चिह्नित किया जाता है। यह Git और अधिकांश diff टूल्स द्वारा उपयोग किया जाने वाला दृष्टिकोण है।

क्या कोई आकार सीमा है?

कोई सख्त सीमा नहीं है, लेकिन बहुत बड़े टेक्स्ट (10,000 से अधिक पंक्तियाँ) को प्रोसेस करने में एक पल लग सकता है, क्योंकि तुलना पूरी तरह आपके ब्राउज़र में चलती है।

«diff» का वास्तव में क्या मतलब है

एक diff describe करता है कि insertions और deletions के smallest set का उपयोग करके एक text को दूसरे में कैसे बदलें। ऐसा करने के infinitely many तरीके हैं, trivial तरीका है «A के हर character को delete करें और फिर B के हर character को insert करें।» एक useful diff shortest edit script है, जो Longest Common Subsequence problem का dual है: वह longest sequence of lines find करें जो दोनों texts में (order में) appear हो, और बाकी सब एक addition या deletion है। अधिकांश diff algorithms अलग hat पहने हुए LCS algorithms हैं।

एक subtle point: longest common subsequence longest common substring नहीं है। Subsequence order preserve करता है लेकिन adjacency नहीं, इसलिए «ABCDE» और «AXBYCZD» subsequence «ABCD» share करते हैं भले ही तीन characters का कोई contiguous run दोनों में न हो।

Diff algorithms का एक संक्षिप्त इतिहास

पहला widely-used file-comparison program Unix diff था जो Bell Labs में Douglas McIlroy ने लिखा था, जिसका underlying algorithm James W. Hunt और McIlroy द्वारा June 1976 में Bell Labs Computing Science Technical Report #41 के रूप में publish किया गया था। McIlroy ने खुद four-month development को «a desperate effort.» के रूप में describe किया। Hunt-McIlroy approach ने file B की हर line को hash किया, index किया कि हर unique line कहां occur हुई, और matches की longest monotonically increasing chain ढूंढी। यह Version 6 Unix में ship हुआ और decades तक अधिकांश Unix systems पर /usr/bin/diff में essentially same algorithm रहा।

Eugene W. Myers ने 1986 में आधुनिक industry standard publish किया, «An O(ND) Difference Algorithm and Its Variations» in Algorithmica Vol. 1, No. 2। Myers ने LCS को एक edit graph के through shortest-path problem के रूप में reframe किया: A को top axis पर और B को side पर रखें, जब भी दो lines match हों एक diagonal draw करें, और top-left से bottom-right तक fewest non-diagonal edges वाला path search करें। हर non-diagonal edge एक insertion या deletion है; हर diagonal free है। Crucially, algorithm O((N+M)·D) time में run करता है जहां D edit script का size है, यानी files जितनी similar होती हैं यह उतना ही faster होता है। Typical version-control diffs के लिए D, N+M की तुलना में tiny है, इसलिए Myers practice में O(N·M) worst case से dramatically faster है। उनके paper में divide-and-conquer trick का उपयोग करके एक linear-space refinement भी है। Myers' algorithm GNU diff, git diff, Mercurial, Subversion, jsdiff, Python के difflib, और अधिकांश GUI diff viewers के default backing है।

Bram Cohen (बाद में BitTorrent के inventor के रूप में बेहतर जाने गए) ने 2002 के आसपास Bazaar version-control system के लिए patience diff design किया। Motivating problem: Myers diff किसी भी matching line को align करता है, common ones सहित, इसलिए C में एक function move करने से एक noisy diff produce हो सकता है जिसमें moved function का closing brace किसी unrelated function के closing brace से align होता है। Patience diff diff को उन lines पर anchor करता है जो हर file में exactly एक बार occur होती हैं (typically function signatures, comment headers, distinctive log messages), केवल उन anchors के LCS को patience sort का उपयोग करके compute करता है, और gaps पर recurse करता है। Result meaningful lines पर align होता है और source code के लिए बेहतर reads होता है। Git इसे git diff --patience के माध्यम से support करता है। Histogram diff git में 2010 के आसपास add किया गया एक refinement है जो line occurrences का histogram build करता है और strictly unique की बजाय low-frequency anchors prefer करता है; git 2.45 से यह कई configurations के लिए default है।

Levenshtein बनाम LCS

जानने योग्य एक related concept। Levenshtein distance (Vladimir Levenshtein, 1965) एक string को दूसरे में बदलने के लिए single-character insertions, deletions, और substitutions की minimum number count करता है। LCS-based diff closely related लेकिन slightly different है: classic diff एक change को single substitution की बजाय delete-then-insert pair के रूप में treat करता है, क्योंकि यह line-oriented files पर better map होता है। Levenshtein का जवाब है «how different are these strings?» और एक number देता है; LCS का जवाब है «what specifically changed?» और एक actual edit script देता है। Spell-checkers और «did you mean?» features पहला चाहते हैं; diff tools दूसरा चाहते हैं। Damerau-Levenshtein variant (1964) typo detection के लिए transposition operator के साथ Levenshtein को extend करता है।

Granularity: line, word, और character

Diff को different granularities पर compute किया जा सकता है, हर एक के trade-offs हैं:

Modern diff UIs में एक common pattern है पहले line level पर diff compute करना, फिर removed/added neighbours के किसी भी pair के लिए केवल उन दो lines पर एक secondary word-level diff run करना और intra-line changes highlight करना। Exactly यही GitHub के PR view और diff-match-patch library दोनों काम करते हैं।

तीन diff display modes जो आप देखेंगे

उपयोगी git diff variants

Browser diff के लिए कब reach करें

वास्तविक सीमाएं

अधिक प्रश्न

यह page changed lines के अंदर character-level highlights क्यों नहीं show करता?

क्योंकि line-level pass अधिकांश use cases के लिए enough है और long inputs पर much faster run करता है। Intra-line word-by-word highlighting के लिए, two-step refinement standard practice है लेकिन latency add करती है। यदि पूरा line difference आपके लिए matter करता है (legal redlining, prose proofreading), तो एक dedicated word-level tool (command line पर git diff --word-diff सहित) better fit है।

Unified diff और side-by-side में क्या अंतर है?

Unified diff वह compact, machine-readable format है जो हर .patch file use करती है, context की तीन lines, hunks @@ के साथ marked। Side-by-side दोनों versions को parallel columns में display करता है, जो visual review के लिए eye पर easier है लेकिन अधिक horizontal space लेता है। Unified वह है जो आप email या commit करते; side-by-side वह है जो आप wide monitor पर read करते।

क्या Myers से source code के लिए बेहतर algorithms हैं?

Moved functions या large rearrangements वाले source code के लिए, हां, patience diff (Bram Cohen, 2002) और histogram diff (git, around 2010) common ones की बजाय meaningful unique lines पर align करने के लिए designed हैं, more readable output produce करते हैं। दोनों git diff --patience और git diff --histogram के माध्यम से available हैं। difftastic जैसे AST-aware tools आगे जाते हैं और actual language structure parse करते हैं।

क्या यहां confidential text paste करना safe है?

हां, diff पूरी तरह आपके browser में एक JavaScript LCS implementation का उपयोग करके run होता है। कुछ upload नहीं होता, input पर कोई analytics नहीं, text का कोई server-side log नहीं। यह एकमात्र category का diff tool है जो NDAs, internal source code, या unreleased contract clauses के लिए safe है; cloud-based diff services जो भी आप paste करते हैं वह देखती हैं।

संबंधित टूल