Learn to read diff

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-05-01

I wanted to find how a certain configuration option changed my Webpack output, which consisted of two files: file1 and file2 (I will use text instead of JavaScript in the examples)

file1:

this is the original text  
line2
line3
line4
happy hacking !

file2 (line3 is deleted and the last line was added)

this is the original text  
line2  
line4  
happy hacking !  
GNU is not UNIX

Normal diff format

Output of $ diff file1 file2

3d2  
< line3  
5a5  
> GNU is not UNIX  

Unified diff format

$ diff -u file1 file2

output:

--- file1        2013-07-06 17:44:59.180000000 +0200  
+++ file2        2013-07-06 17:39:53.433000000 +0200  
@@ -1,5 +1,5 @@  
 this is the original text  
 line2  
-line3  
 line4  
 happy hacking !  
+GNU is not UNIX  

Here's another example:

output:

13. @@ -9,3 +9,4 @@
14.  source /home/vagrant/.profile  
15.  
16.  nvm install node  
17. +nvm alias default node

Colored output

To get colored diff, pipe into vim: $ diff application*.js | nvim -

References