git blame <file> hiển thị mỗi dòng: commit hash, author, date, line content — ai viết dòng đó khi nào.
Use cases thực sự hữu ích:
1. Hiểu context của code lạ:
git blame src/utils/pricing.ts -L 23,35
# Thấy: dòng 28 được viết bởi john 6 tháng trước
# git show <hash> → xem full commit, đọc message, hiểu lý do**2.
Tìm commit introduce bug:**
git blame -w src/auth.ts # -w: ignore whitespace changes
git blame -M src/auth.ts # -M: detect moved lines
git blame -C src/auth.ts # -C: detect copied lines from other files3. Trong VSCode/IDE: GitLens extension hiển thị blame inline → hover để xem commit, click để open PR → truy ngược decision history.
4. Khi integrate với external PR/issue tracker:
git log --follow -p src/payments/stripe.ts
# Xem full history kể cả khi file bị rename**5.
Security audit**: tìm khi nào secret/credentials bị commit vào:
git log -S "password=" --all -pLưu ý: blame thường trỏ về commit "refactor" hay "format code" — dùng git log --follow và -w để skip qua những thay đổi không có ý nghĩa, tìm commit thực sự thay đổi logic.
git blame <file> shows for each line: commit hash, author, date, and line content — who wrote that line and when.
Genuinely useful use cases:
1. Understanding unfamiliar code:
git blame src/utils/pricing.ts -L 23,35
# See: line 28 was written by john 6 months ago
# git show <hash> → view full commit, read message, understand the reason**2.
Finding the commit that introduced a bug:**
git blame -w src/auth.ts # -w: ignore whitespace changes
git blame -M src/auth.ts # -M: detect moved lines
git blame -C src/auth.ts # -C: detect lines copied from other files3. In VSCode/IDE: GitLens shows blame inline → hover to see the commit, click to open the PR → trace decision history.
4. When integrating with external PR/issue trackers:
git log --follow -p src/payments/stripe.ts
# Full history even when the file was renamed**5.
Security audit**: find when secrets/credentials were committed:
git log -S "password=" --all -pNote: blame often points to "refactor" or "format code" commits — use git log --follow and -w to skip past meaningless changes and find the commit that actually changed logic.