tekin.co.uk

Git tip: committing with verbose mode

Today I want to talk about a little-know flag for the git commit command that I think will help you create better commits: -v, also known as --verbose. Use this flag and Git will include the diff of the changes at the bottom of the commit message template:

An example of the Git commit message template including the verbose output

I think this is helpful for a couple of reasons.

Firstly it gives you useful context for writing a helpful commit message. Seeing the changes may remind you of a particular aspect of the change that needs explaining or context that would be useful to capture.

Secondly it gives you the opportunity to perform a final sense check before you create the commit. You may spot a typo, or a change that doesn’t really sit with the rest of the changes. Or perhaps seeing all the changes together triggers a spark of inspiration for a better way to do what you are trying to do.

Configure Git to always use verbose mode

You can save yourself from having to remember to type -v by configuring Git to always show the verbose output when you run git commit:

  $ git config --global commit.verbose true

Configure your editor to syntax-highlight the diff

You can also configure your to editor syntax-highlight the diffs to make them easier to parse:

  • Atom users can install the language-diff package
  • Sublime Text users can install the Git Commit Message Syntax plugin
  • The TextMate and Visual Studio Code users amongst you get highlighted diffs straight out of the box

And if you haven’t actually configured Git to use your editor of choice when you run git commit, GitHub have a handy guide for exactly how to do this.

Want more juicy Git tips like this straight to your inbox?

You'll get an email whenever I have a fresh insight or tip to share. Zero spam, and you can unsubscribe whenever you like with a single click.

More articles on Git

Authored by Published by