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 do ai viết 6 tháng trước → git show <hash> đọc full commit message, hiểu lý do.
2. Truy vết chính xác hơn với flags:
git blame -w src/auth.ts # -w: bỏ qua whitespace changes
git blame -M src/auth.ts # -M: detect dòng bị move trong file
git blame -C src/auth.ts # -C: detect dòng copy từ file khác3. Trong VSCode/IDE: GitLens extension hiển thị blame inline → hover để xem commit, click để open PR → truy ngược decision history.
4. File bị rename: git log --follow -p src/payments/stripe.ts — xem full history kể cả khi file đã đổi tên.
5. Security audit: git log -S "password=" --all -p — tìm khi nào secret/credentials bị commit vào.
Lư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.