Find when (and why) something changed
safe intermediate #blame#log#search#history
When to use this: A line, file or word changed and you want to know which commit did it.
Before you start
Steps
-
History of one file
terminalgit log --oneline --follow -- src/pages/index.astroLists the commits that touched that file.
--followkeeps tracking it across renames. -
See the actual edits to that file
terminalgit log -p -- src/pages/index.astroAdds the diff of each commit. Scroll with space, quit with
q. -
Which commit added or removed a piece of text?
terminalgit log -S"heroTitle" --oneline-S(the 'pickaxe') finds commits where the number of occurrences of that text changed. -
Who last changed each line?
terminalgit blame src/pages/index.astroPrefixes every line with the commit and author that last modified it. Then
git show <id>to read the whole commit. -
What did I do in a time window?
terminalgit log --since="2 weeks ago" --author="Your Name" --onelineHandy for a weekly summary. Dates like
yesterdayor2025-01-01also work.
How to verify it worked
- You have a commit ID, and
git show <id>explains the change.
Q&A
How do I get back a file as it was in an old commit?
git restore --source=<commit> -- path/to/file copies that version into your working tree. Then review with git diff and commit if you want to keep it.