AI Hints
Home›Git & GitHub Tutorial›Aliases and Searching
Git & GitHub · Lesson 96 of 144

Searching History

Find any commit.

⏱ 2 min read▶ Video at 1:45:13🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

After a year, a project might have thousands of commits. When you need to find one, scrolling isn't an option. Git log has powerful search options.

Searching History
From the video: Searching History
  • Thousands of commits
  • Scrolling won't work
  • git log can search

Search messages and authors

Dash dash grep searches commit messages. Here, every commit mentioning contact. Dash dash author shows commits by one person. And dash dash since, with a date and time, shows only the commits made after it.

git
git log --oneline --grep contact
4a9b0f8 (HEAD -> main) Link to contact page
f4ffcb2 Add contact form
e45fb4b Add contact page
git log --oneline --author "Sam" -n 3
4a9b0f8 (HEAD -> main) Link to contact page
f4ffcb2 Add contact form
e45fb4b Add contact page
git log --oneline --since "2026-01-05 09:30"
4a9b0f8 (HEAD -> main) Link to contact page
f4ffcb2 Add contact form
e45fb4b Add contact page

Search the code itself

Even more powerful, capital dash S searches the changes themselves. It finds commits that added or removed some text. Which commit added the form? Dash S form tells us. It was add contact form. And git grep searches the files right now, showing every line that contains a word.

git
git log --oneline -S "<form>"
f4ffcb2 Add contact form
git grep -n contact
index.html:4:<a href="contact.html">Contact</a>

Search options

Here are the search options together. Grep, for words in the message. Author, for a person. Since and until, for dates. Capital S, for text added or removed in the code. And a file name at the end, for one file's history.

OptionFinds commits...
--grep wordwith word in the message
--author nameby that person
--since / --untilin a date range
-S textadding or removing text
-- filetouching that file

Summary

Git log can search by message, author, date, code changes and file. Git grep searches your current files. Next, a popular style for commit messages.

Key takeaways
  • --grep, --author, --since
  • -S finds code changes
  • git grep searches files
Next up: Conventional Commits — a common message style