Trung BìnhGit iconGit

`git blame` trong thực tế: nó không chỉ để "đổ lỗi" — những use case thực sự hữu ích là gì?

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ạ:

bash
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:**

bash
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 files

3. 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:

bash
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:

bash
git log -S "password=" --all -p

Lưu ý: blame thường trỏ về commit "refactor" hay "format code" — dùng git log --follow-w để skip qua những thay đổi không có ý nghĩa, tìm commit thực sự thay đổi logic.

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git