Skip to main content

Command Palette

Search for a command to run...

Finding a bug by checking git history one commit at a time

Updated
2 min read
Finding a bug by checking git history one commit at a time

I’m far from a command line wizard, but am gradually picking up more tricks and tips as time goes by.

I recently found a styling bug I was confident I’d introduced in the previous few commits, but I wasn’t sure which one. In the past I’ve used git bisect but on this occasion I took a different approach. I knew I wouldn’t have to go back many commits, but I wasn’t sure how far back to go in order to be confident of finding working code (which is necessary for git bisect). I decided to go back through my git history one commit at a time and test each time. The bug was in a vue app and I wasn’t confident whether or not hot reloading would work given the nature of the changes, so I stopped the app each time and served it again.

The approach I took was to simply run the following command repeatedly, testing the app each time:

git checkout HEAD~1; npm run serve

This checks out the previous commit (which is what HEAD~1 means) then runs the serve script from the project’s package.json file. While the bug was still present, I simply stopped the script and reran it which moved me back again to the previous commit.

I don’t often use the HEAD~1 syntax in git but I’m becoming more familiar and confident with it, and finding more occasions where it’s useful to me. I’m also becoming gradually more confident combining commands using ;, and this was a good example of a case when even a short time ago I wouldn’t have been able to do this so simply.

More from this blog

T

Tim talks tech

76 posts