brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git bisect with old and new finds when something changed, not just when it broke

Git
~/tips/tip-git-bisect-old-new-terms

git bisect new HEAD

Uses bisect to find the commit that introduced any change, even a good one.

Bisect talks about good and bad commits, which feels wrong when you’re looking for the commit that fixed something or made a page faster. Git lets you swap those words.

git bisect start
git bisect new HEAD
git bisect old v1.0

old and new are built-in alternatives to good and bad. “New” is the state you see now, “old” the state from before. So to find which commit fixed a bug that’s gone now, I’d mark today as new and an old release as old, and bisect walks to the commit where the behaviour flipped. With good and bad that question reads backwards and it is easy to mix them up halfway.

You can also pick your own words when you start:

git bisect start --term-old=slow --term-new=fast HEAD v1.0
git bisect fast
git bisect slow

After that, git bisect fast and git bisect slow mark commits. If you forget which words you chose, git bisect terms prints them. git bisect reset ends the session like always.

The rule stays the same: the old state has to be an ancestor of the new state, and the change has to happen once. If the behaviour flipped back and forth a few times, bisect finds one of those flips, not necessarily the one you mean. And within one session you can’t mix the pairs: once you’ve used old, bad isn’t accepted.

Further reading: git-bisect documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link