Git Academy

Intermediate · 6 min read

Search the history like a detective

Who changed this, when, why — and what did this file look like last month?

Filter the log

By author, date, message, or file. Combine them freely.

Safe
$ git log --oneline --author="Alice" --since="1 month ago" --grep="login" -- src/auth

Find when code appeared or disappeared

-S searches commits that changed the number of occurrences of a string: perfect to find who deleted a function.

Safe
$ git log -S "function refreshToken" --oneline

Who wrote this line, and why

blame gives the last commit of each line; then git show that commit to read its message and full change.

Safe
$ git blame -L 40,60 src/auth/session.ts
$ git show <commit>

An old version of a file

Read it without changing anything, or restore it in your working copy.

Safe
$ git show HEAD~10:src/config.ts
$ git restore --source=HEAD~10 -- src/config.ts