Git blame

Git blame

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

git blame <file>

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:

git blame app.dart

Output:

e8a1c6f3 (Alice 2024-01-10 14:23:55) import 'package:flutter/material.dart'; a3b5f4d2 (Bob 2024-02-02 09:12:43) void main() { d4c7e8a1 (Alice 2024-02-10 16:45:22) runApp(MyApp());

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

git blame -L 5,10 app.dart

📌 This shows the authorship of lines 5 to 10.

🔹 Ignore Whitespace Changes

git blame -w app.dart

📌 Useful when changes involve only spaces or indentation.

🔹 Show Commit Messages with Blame

git blame -c app.dart

📌 Displays commit hashes in full for easy reference.

🔹 View Blame in a Graphical Interface

git gui blame app.dart

📌 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? 😊

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close