Git Blame: Track Line-by-Line Changes in a File
git blame
is a powerful Git command that helps you track who made changes to each line of a file and when. It is useful for debugging, understanding code history, and identifying the authors of specific changes.
1. Basic Syntax
This command displays the author, commit hash, and timestamp for each line of the specified file.
2. Example Usage
Suppose you want to check who modified app.dart
:
Output:
Each line shows:
- Commit hash (e.g.,
e8a1c6f3
) - Author name (e.g.,
Alice
) - Date & time of change (e.g.,
2024-01-10 14:23:55
) - Code line content (e.g.,
import 'package:flutter/material.dart';
)
3. Useful Options
🔹 Show Blame for a Specific Line Range
📌 This shows the authorship of lines 5 to 10.
🔹 Ignore Whitespace Changes
📌 Useful when changes involve only spaces or indentation.
🔹 Show Commit Messages with Blame
📌 Displays commit hashes in full for easy reference.
🔹 View Blame in a Graphical Interface
📌 Opens Git GUI for better visualization.
4. When to Use git blame
?
✅ Find out who changed a specific line of code
✅ Debugging issues by checking recent modifications
✅ Understanding why a change was made
✅ Contacting the author for clarification on a change
5. Alternative: GitHub & GitLab Blame
If you're using GitHub or GitLab, you can also use their web UI:
- GitHub → Open a file and click "Blame" at the top-right.
- GitLab → Open a file and click "Blame" in the top menu.
🔹 Conclusion
The git blame
command is essential for understanding the history of changes in a file. It helps in debugging, accountability, and collaboration.
Do you want to see how to combine it git blame
with git log
for deeper insights? 😊