📘Cisco DevNet Associate (200-901 DEVASC)
What is a Unified Diff?
A unified diff is a format used to show the differences between two files, usually a source code file or a configuration file. It’s a common output when using tools like Git, diff, or other version control systems.
- The unified diff shows what changed, what was added, and what was removed.
- It’s called “unified” because it combines context (unchanged lines) with changes in a single view. This makes it easier to understand the difference between file versions.
In IT, this is used for:
- Reviewing changes in network configurations.
- Comparing API scripts or automation scripts before deployment.
- Code reviews in DevOps pipelines.
Anatomy of a Unified Diff
Here’s an example of a unified diff output:
@@ -2,7 +2,7 @@
interface GigabitEthernet0/1
- ip address 192.168.1.1 255.255.255.0
+ ip address 192.168.1.2 255.255.255.0
description Link to Core Switch
Let’s break this down step by step.
1. Hunk Header
@@ -2,7 +2,7 @@
@@marks the start of a hunk (a block of changes).-2,7→ The original file: starts at line 2 and spans 7 lines.+2,7→ The new file: starts at line 2 and spans 7 lines.- Essentially, this tells you where the changes occur in both files.
Why important for IT?
It helps you locate exactly which part of a configuration or script was modified.
2. Context Lines
interface GigabitEthernet0/1
description Link to Core Switch
- Lines without
+or-are context lines. - These lines did not change but are included to give context to the changes.
- In network scripts, this could be interface definitions, routing statements, or firewall rules.
3. Removed Lines
- ip address 192.168.1.1 255.255.255.0
- Lines that start with a minus (-) indicate that this line was removed from the original file.
Example: Old IP configuration was removed.
4. Added Lines
+ ip address 192.168.1.2 255.255.255.0
- Lines that start with a plus (+) indicate that this line was added in the new file.
Example: IP was updated to a new value in the network configuration.
How to Read a Unified Diff Step by Step
- Look at the hunk header (
@@ -2,7 +2,7 @@) to locate where the change is. - Check removed lines (-) to see what was deleted.
- Check added lines (+) to see what was inserted.
- Look at context lines to understand how the changes fit in the overall file.
Real IT Use Cases
- Configuration Management
- Compare old and new Cisco IOS configurations before applying updates.
- Prevent mistakes like changing the wrong IP or interface settings.
- Automation Scripts
- Review changes in Python scripts for API calls or Ansible playbooks.
- Understand which modules or parameters were modified.
- Version Control
- DevOps teams use Git diffs to review pull requests.
- Unified diffs help detect syntax errors or misconfigurations before deployment.
Tips for the Exam
- Remember symbols:
-→ line removed+→ line added- No symbol → unchanged/context
- Understand hunk headers:
@@ -a,b +c,d @@→a=start line original,b=lines in original,c=start line new,d=lines in new.
- Focus on context:
- Unified diffs always include some unchanged lines to give perspective.
- Don’t ignore context—it’s part of interpreting changes correctly.
- Check multiple hunks:
- A file can have multiple hunks, each showing changes in different parts of the file.
Summary Table
| Symbol | Meaning | Example in IT Context |
|---|---|---|
- | Removed | Old IP address or firewall rule removed |
+ | Added | New IP address or firewall rule added |
(space) | Context | Interface name, VLAN, or route that did not change |
@@ | Hunk header | Shows line numbers of changes |
Key Takeaway:
A unified diff is just a clear way to see what changed in a file. In IT environments, it’s used for reviewing network configs, automation scripts, or code changes. For the exam, make sure you can read the symbols, interpret the hunk headers, and understand the context of changes.
