appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Tags, history and finding bugs

Lesson 4 of 410 minIntermediate

Mark releases, search history and use bisect to find the commit that broke something.

Tags

A tag gives a fixed name to a commit, typically a release.

git tag -a v1.2.0 -m "Release 1.2.0"
git push origin v1.2.0
git tag --list

Search the history

git log --oneline --graph --decorate -20
git log -S"timeout" -- app.py     # commits that added or removed that text
git blame app.py                  # who changed each line, and when
git show 3f2a9c1                  # one commit in full

git bisect

You know the code worked in an old version and is broken now, but not which commit broke it. git bisect does a binary search through the history.

git bisect start
git bisect bad                 # current commit is broken
git bisect good v1.1.0         # this one worked
# Git checks out the middle commit. Test it, then answer:
git bisect good   # or: git bisect bad
# ...repeat until Git names the first bad commit
git bisect reset

With 1,000 commits between the two points, bisect needs only about 10 tests.

Notegit bisect run ./test.sh automates it: the script must exit 0 for good and non-zero for bad.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. About how many steps does bisect need over 1,000 commits?
2. Which command shows who last changed each line of a file?
Hintgit log --oneline with a count.

Key terms