Code-Diff
This article is a glossary entry on the topic of Code-Diff – including brief exam questions, typical practical examples, and suitable tags for quick revision.
What is a Code-Diff?
A Code-Diff shows the differences between two versions of a file or code state. In practice, a diff is mainly used for:
- Version control (e.g. Git)
- Code reviews (feedback on changes)
- Error detection (What has changed since the last working state?)
- Traceability and documentation
How is a Diff used in Git and in Teams?
In teams, a diff is the common basis for understanding changes:
- Pull Requests display diffs so that reviewers can comment precisely.
- CI/CD can select tests or check rules based on modified files.
- Security/Compliance: Diffs help prevent sensitive data (tokens, passwords) from being accidentally committed.
How to Read a Diff? (+ / -)
The so-called Unified Diff format is typical:
-marks removed lines (old)+marks added lines (new)
Simple Example
- print("Hallo Welt")
+ print("Hallo Welt!")
+ print("Programmstart erfolgreich.")
Explanation: The first line was changed (exclamation mark). Additionally, two new lines were added.
Advantages and Disadvantages
Advantages
- Changes are quickly visible
- Very good for reviews and quality assurance
- Helps with bug fixes because the scope of changes becomes clear
Disadvantages
- Large changes are hard to read
- Without context, you sometimes don’t understand why something was changed
- Often not useful for binary files (images, PDFs)
Typical Exam Questions (with Short Answers)
- What is a Code-Diff? A side-by-side comparison of code changes between two versions.
- How do you create a diff in Git?
With
git diff, e.g.git diff HEAD~1. - What do
+and-mean?+is newly added,-was removed. - Why is a diff important in code review? Because reviewers can precisely see what was changed and provide feedback.
Conclusion
A Code-Diff is more than just a comparison: it is a central tool for team communication, quality assurance, and traceability in software projects.