How to read a Diff
If you havenβt worked with diffs before, this can be something quite new or different.
If we have two files, letβs say a grocery list, in two files. Weβll call them βaβ and βbβ.
Input: Old$ cat old π π π π π π₯
Output: New$ cat new π π π π π π₯
We can see that they have some different entries. Weβve removed π because theyβre awful, and replaced them with an π
Diff lets us compare these files
$ diff old new
5c5
< π
---
> π
Here we see that π is only in a, and π is only in b. But otherwise the files are identical.
There are a couple different formats to diffs, one is the βunified diffβ
$ diff -U2 old new
--- old 2022-02-16 14:06:19.697132568 +0100
+++ new 2022-02-16 14:06:36.340962616 +0100
@@ -3,4 +3,4 @@
π
π
-π
+π
π₯
This is basically what you see in the training materials which gives you a lot of context about the changes:
--- old
is the βoldβ file in our view+++ new
is the βnewβ file- @@ these lines tell us where the change occurs and how many lines are added or removed.
- Lines starting with a - are removed from our βnewβ file
- Lines with a + have been added.
So when you go to apply these diffs to your files in the training:
- Ignore the header
- Remove lines starting with - from your file
- Add lines starting with + to your file
The other lines (π/π and π₯) above just provide βcontextβ, they help you know where a change belongs in a file, but should not be edited when youβre making the above change. Given the above diff, you would find a line with a π, and replace it with a π
Added & Removed Lines
Removals are very easy to spot, we just have removed lines
--- old 2022-02-16 14:06:19.697132568 +0100
+++ new 2022-02-16 14:10:14.370722802 +0100
@@ -4,3 +4,2 @@
π
π
-π₯
And additions likewise are very easy, just add a new line, between the other lines in your file.
--- old 2022-02-16 14:06:19.697132568 +0100
+++ new 2022-02-16 14:11:11.422135393 +0100
@@ -1,3 +1,4 @@
π
+π
π
π
Completely new files
Completely new files look a bit different, there the βoldβ file is /dev/null
, the empty file in a Linux machine.
$ diff -U2 /dev/null old
--- /dev/null 2022-02-15 11:47:16.100000270 +0100
+++ old 2022-02-16 14:06:19.697132568 +0100
@@ -0,0 +1,6 @@
+π
+π
+π
+π
+π
+π₯
And removed files are similar, except with the new file being /dev/null
--- old 2022-02-16 14:06:19.697132568 +0100
+++ /dev/null 2022-02-15 11:47:16.100000270 +0100
@@ -1,6 +0,0 @@
-π
-π
-π
-π
-π
-π₯
Still have questions?
Want to embed this snippet (FAQ) in your GTN Tutorial?
{% snippet topics/admin/faqs/diffs.md %}