Failure is inevitable


Git Tips & Tricks, Part 5–Checking Your Commit for TODOs

Today’s simple tip will show you how to check for lingering “TODO” comments before you push your code up to your shared repository.

Have you ever dropped a TODO in your code to remind you to come back and refactor or clean something up later?  I’ll do that quite often when I’m hashing out changes for a new feature or bugfix:

File 2 content!
This is File 2, Line 2!
//TODO: Come back and add more lines!

I’ll usually clean those up pretty quickly, but sometimes I forget to go back and get them all.  Fortunately, git makes it very easy for me to find any lingering TODOs.  Just run this command from your posh-git console:

git show HEAD | sls -SimpleMatch "TODO" -Context 5

If your last commit included any new TODOs, you’ll see the relevant block of the commit, and you can investigate further.   You can scan an older commit by substituting the commit’s hash in place of “HEAD” in the command above.

About Matt Honeycutt...

Matt Honeycutt is a software architect specializing in ASP.NET web applications, particularly ASP.NET MVC. He has over a decade of experience in building (and testing!) web applications. He’s an avid practitioner of Test-Driven Development, creating both the SpecsFor and SpecsFor.Mvc frameworks.

He's also an author for Pluralsight, where he publishes courses on everything from web applications to testing!

blog comments powered by Disqus