tips
12 tips Diff
One command, setting or habit at a time about Diff: what it does, the line to copy and a caveat or two.
Linux and shell 10
-
Leaves out files and folders matching a pattern when comparing two directories recursively.
diff -r -x .git -x '*.log' one two -
Puts two versions next to each other in columns, which is easier to read for short config files.
diff -y -W 100 old.conf new.conf -
Creates a patch of a whole folder that includes new and deleted files, not only changed ones.
diff -Naur original/ changed/ > fix.patch -
Tests a patch file against your folder first, so a failed patch doesn't leave half-changed files.
patch -p1 --dry-run < ../fix.patch -
Compares a Windows file with a Unix file without every line showing up as changed.
diff --strip-trailing-cr windows.txt unix.txt -
Uses diff's exit code to act only when a file really changed.
if ! diff -q /etc/nginx/nginx.conf /srv/backup/nginx.conf > /dev/null; then -
Leaves out changes in lines such as generated dates, so two exports can be compared.
diff -I '^# generated' old/app.conf new/app.conf -
Hides differences that are only extra or fewer spaces, so the real changes stand out.
diff -b old.conf new.conf -
Compares two folder trees and lists only the files that are missing or changed.
diff -qr /srv/site /mnt/backup/site -
Compares the output of two commands directly, without saving them to temporary files.
diff
Git settings and fixes 2
-
Adds the original text to merge conflicts so you can see what each side changed.
git config --global merge.conflictStyle zdiff3 -
Switches Git's diff algorithm so moved or repetitive code can show up as cleaner hunks.
git diff --diff-algorithm=histogram
Nothing in this filter yet.