Can I use git diff on untracked files?

With recent git versions you can git add -N the file (or –intent-to-add), which adds a zero-length blob to the index at that location. The upshot is that your “untracked” file now becomes a modification to add all the content to this zero-length file, and that shows up in the “git diff” output. git diff … Read more

What is `git diff –patience` for?

You can read a post from Bram Cohen, the author of the patience diff algorithm, but I found this blog post to summarize the patience diff algorithm very well: Patience Diff, instead, focuses its energy on the low-frequency high-content lines which serve as markers or signatures of important content in the text. It is still … Read more

Python – difference between two strings

You can use ndiff in the difflib module to do this. It has all the information necessary to convert one string into another string. A simple example: import difflib cases=[(‘afrykanerskojęzyczny’, ‘afrykanerskojęzycznym’), (‘afrykanerskojęzyczni’, ‘nieafrykanerskojęzyczni’), (‘afrykanerskojęzycznym’, ‘afrykanerskojęzyczny’), (‘nieafrykanerskojęzyczni’, ‘afrykanerskojęzyczni’), (‘nieafrynerskojęzyczni’, ‘afrykanerskojzyczni’), (‘abcdefg’,’xac’)] for a,b in cases: print(‘{} => {}’.format(a,b)) for i,s in enumerate(difflib.ndiff(a, b)): if s[0]==’ ‘: … Read more

recursive array_diff()?

There is one such function implemented in the comments of array_diff. function arrayRecursiveDiff($aArray1, $aArray2) { $aReturn = array(); foreach ($aArray1 as $mKey => $mValue) { if (array_key_exists($mKey, $aArray2)) { if (is_array($mValue)) { $aRecursiveDiff = arrayRecursiveDiff($mValue, $aArray2[$mKey]); if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; } } else { if ($mValue != $aArray2[$mKey]) { $aReturn[$mKey] = $mValue; } … Read more

git-diff to ignore ^M

GitHub suggests that you should make sure to only use \n as a newline character in git-handled repos. There’s an option to auto-convert: $ git config –global core.autocrlf true Of course, this is said to convert crlf to lf, while you want to convert cr to lf. I hope this still works … And then … Read more

Diff Algorithm? [closed]

An O(ND) Difference Algorithm and its Variations is a fantastic paper and you may want to start there. It includes pseudo-code and a nice visualization of the graph traversals involved in doing the diff. Section 4 of the paper introduces some refinements to the algorithm that make it very effective. Successfully implementing this will leave … Read more