How to Rock Code Review on the Command Line

Recently I’ve focused on utilising the command line more whilst learning how to use Git outside a GUI. Through this I’ve found what can only be described as the ultimate code review command!! along with an approach I like for assessing changes.

Most of the time code reviews can feel overwhelming, especially as branches get larger and diverge further from the develop branch, and to be honest it tends to be easier to sit down with the developer and have them highlight where to focus your attention rather than trawl through days of bug fixing commits.

However if your the anti-social sort; or, like me, get a warm fuzzy feeling when rocking the command line; here’s a guide to the ultimate code review git command.

Step 1: Download and Setup Console2

What is Console2? It’s a command prompt / Powershell replacement that comes with some pretty awesome features, including:

  • Tabbed interface with all the wonder of Ctrl+T and Ctrl+Tab for working across multiple sessions
  • Fully customisable font, colour, freaking transparency
  • Set your own keyboard shortcuts. That’s right, you can finally Ctrl+V into the console
  • Fully resizable windows that adjust the buffers in real time
  • Different profiles for new tabs; including changing working directory, icons etc

Scott Hansleman wrote a setup article about it a while ago that still works nicely with the latest version; see here for his install guide.

Pro-tip: this is the version you want. I accidentally downloading the older and much worse version first time)

Step 2: Downland and Setup VIM

VIM? That’s right we’re going proper poweruser / geek today. I say VIM as it integrates very nicely with Console2. Sure it takes time to learn the shortcuts; but for what we’re about to do it’s perfect.

You can download the latest version here

Then add VIM to your system path variable and you’re good to go on the command line.

Step 3: The Command!

Open up Console2 with a Powershell tab. If you’ve just added VIM to your path I recommend restarting Console2 so the path variable is refreshed.

Then run a command line this badboy whilst inside a Git repository

git log --author=Luke* --after="2015-01-01 10:00" -p --reverse | vim -

This will:

  • git log - Return a list of commits on your currently checked out branch
  • –author=Bob* - Limited only to commits made by people with the firstname “Bob”
  • –after=”2015-01-01 10:00″ - Limited only to commits after this date; useful for filtering out
  • -p - Show a diff of the changes made in that specific commit
  • –reverse - Present the commits in date order ascending so the earlier changes are shown first
  • | vim – - Pipes the whole data set into a VIM window for you to review

I find it immensly useful to go through a filtering list of commits in the order they were made; whilst VIM does a great job of highlighting the differences (it syntax highlights the diff automatically).


Update: Better Command

I’ve been playing with this a while and found a slightly better and less manual command to use:

git log origin/develop..head -p --reverse | vim -

This will output all commits not merged into origin/develop with the same output style as above. It’s a bit easier to use as you don’t have to add author or date.