Git blame: who modified this line?
git blame shows the author, date and commit for each line of a file. An essential tool for understanding the history of your code.
gitquest — enquête
What does git blame show?
Anatomy of a blame line
a1b2c3d4(Anais2024-01-15 14:30)5)<meta charset="utf-8">
Hash
The commit that modified this line
Author
Who made the change
Date
When the change was made
Line
The line number
Git blame in practice
Basic blame and advanced options.
Basic blame
gitquest — blame
# See who modified each line of a file
$git blame index.html
a1b2c3d4 (Anais 2024-01-15 14:30) 1) <!DOCTYPE html>
a1b2c3d4 (Anais 2024-01-15 14:30) 2) <html lang="fr">
f5e6d7c8 (Marie 2024-02-20 09:15) 3) <head>
f5e6d7c8 (Marie 2024-02-20 09:15) 4) <title>MySite</title>
b9c0d1e2 (Anais 2024-03-10 16:45) 5) <meta charset="utf-8">
# Each line shows: hash, author, date, line number, content
Useful options
gitquest — blame options
# Blame on a line range (lines 10 to 20)
$git blame -L 10,20 index.html
c3d4e5f6 (Pierre 2024-03-01 11:00) 10) <nav>
c3d4e5f6 (Pierre 2024-03-01 11:00) 11) <ul>
# Ignore whitespace/indentation changes
$git blame -w index.html
# Track code even if it was moved from another file
$git blame -C index.html
Detected code moved from header.html
Essential blame options
git blame <file>Full blame of a file
git blame -L 10,20 <file>Blame lines 10 to 20 only
git blame -w <file>Ignore whitespace changes
git blame -C <file>Detect code copied from other files
git blame --since="2 weeks"Blame since a given date
git blame --ignore-rev <hash>Ignore a commit (e.g. reformatting)
Part of the Git History, Search & Debug guide
A
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git blame
Practice Git commands in GitQuest
GitQuest investigations teach you to explore code history to solve mysteries.
Start the investigations