Find who changed a line and why
I want to know which commit introduced a line.
The problem
I want to know which commit introduced a line.
How the practice repository looked before
## main
45bcfeb Add name 78b430b Raise rate to 7 for new plan bac45a9 Start
The fix
78b430b (Demo User 2026-01-04 10:00:00 +0000 1) rate = 7 45bcfeb (Demo User 2026-01-05 10:00:00 +0000 2) name = demo
78b430b Raise rate to 7 for new plan
Why this works
git blame prints each line with the commit that last changed it. git log -S"text" lists the commits that added or removed that text, which is the quicker way to find where something first appeared.
If this is not quite your case
Add -L 1,5:file to git blame to look at just lines 1 to 5, and -w to ignore white-space changes. git log -p -S"text" also prints the changes, so you can read exactly how the text appeared. Then git show <hash> shows the whole commit.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.