Git from Zero to Hero — Part 2: Understanding Diff (What Changed?)
>>> Previous: Part 1 — What is Version Control?
What is Diffing?
In the previous part, we talked about Version Control.
Now let’s understand a key concept behind it:
Diffing
Diffing means comparing two files and finding out what has changed between them.
Why Do We Need Diff?
Imagine you have two Python files:
prog_buggy.py→ original versionprog_correct.py→ bug-fixed version
Now the question is:
What exactly changed?
Manual vs Automatic Comparison
One way is to compare them manually:
Open both files
Put them side by side
Check line by line
But this is slow and error-prone.
Instead, we use a tool called diff.
Basic Diff Command
diff prog_buggy.py prog_correct.py
This command shows the difference between two files.
Example:
10c10
< return total / (len(numbers) - 1)
---
> return total / len(numbers)
What does this mean?
<→ line removed from the first file>→ line added in the second file10c10→ line 10 changed
Multiple Changes Example
10c10,11
< return total / (len(numbers) - 1)
---
> # bug fixed here
> return total / len(numbers)
29c30
< main()
---
> main()
This means:
One line changed into two lines
Another change happened later in the file
Side-by-Side Comparison
If you want a visual comparison:
diff -y prog_buggy.py prog_correct.py
This shows both files side by side.
Unified Format (Most Popular)
Developers often use:
diff -u prog_buggy.py prog_correct.py
Example:
@@ -7,7 +7,8 @@
- return total / (len(numbers) - 1)
+ # bug fixed
+ return total / len(numbers)
Meaning:
→ removed lines
→ added lines
Why is Diff Important?
Diff helps us:
Understand changes quickly
Track bugs and fixes
See exactly what was modified
And most importantly:
>>> Git uses this concept internally
Bonus: Useful Tools
Some tools that help visualize differences:
kdiff3
meld
wdiff
Final Thought
Learning how to read diff output is a very useful skill.
It will help you understand Git much better.
Next: Part 3 — Working with Patch

