Compare two texts
The difference between two texts or configs by line and by word, as a diff -u patch.
Difference
The texts are identical.
Calculated in your browser — nothing is sent to the server
Practice on a machine
Lab “Change an address everywhere”
In a Linux terminal
cp nginx.conf nginx.conf.bak
# a copy before editing
diff -u nginx.conf.bak nginx.conf
# the difference as a patch
diff -w a.conf b.conf
# ignore whitespace
diff -rq /etc/nginx /backup/nginx
# which files differ between directories
git diff --no-index --word-diff a.txt b.txt
# by word, even outside a repository
Keep in mindTrailing spaces and Windows line endings (CRLF) count as changes too, even when the lines look the same.
How to read diff -u
---and+++are the old and the new file.@@ -1,4 +1,5 @@is a hunk: 4 lines from line 1 in the old file, 5 in the new one.-marks a removed line,+an added one, a space an unchanged one.
FAQ
Why are identical lines marked as changed?
They differ in something invisible: a trailing space, a tab, a \r\n line ending. If the mark goes
away with “Ignore spaces”, whitespace is the cause.
How do I compare two files?
Paste their contents into “Before” and “After”. On a server, run diff -u file1 file2.
How do I apply the patch?
Save it to a file, fix the file names in the --- and +++ lines and run patch -p0 < file.patch.
Try --dry-run first.