Lesson 7 of 8

Reading History

Learn to search your project's history to find who changed a line, what changed last week, and which commit introduced a .

Bash
git log --oneline            # compact history
git log -p index.js          # commits + diffs for one file
git log --author="Ada"       # filter by author
git log --since="2 weeks ago"
git log -S "parseConfig"     # commits that added/removed this string

git show a1b2c3d             # everything about one commit

# Who last touched each line of a file, and in which commit:
git blame src/auth.js

bisect deserves special mention: it -searches history for the commit that introduced a bug. Mark one good commit and one bad commit, and git checks out the midpoint; you test and say good or bad; repeat. A thousand commits is only ~10 tests.

Bash
git bisect start
git bisect bad               # current version is broken
git bisect good v1.2.0       # this old tag worked

# Git checks out a middle commit. Test your app, then:
git bisect good    # or: git bisect bad
# ...repeat until:
# a1b2c3d is the first bad commit

git bisect reset             # back to where you started
Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.