Read more

Git: When committing, check the diff

Arne Hartherz
August 29, 2012Software engineer at makandra GmbH

When committing, you should always check the diff of your changes so you don't include any leftovers or irrelevant/bad changes. Any time spent on that is well invested as it saves you rejected merge requests or any mess you need to clean up later.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

While you can just use git diff or git diff --cached (to diff staged changes), you can also have Git include the changes as a comment below the commit message:

git commit -v

That will open up the usual commit "file" in your preferred text editor, but it will include a diff below the status comment. Vim will understand and properly highlight the diff.

You should go ahead and define an alias (in your ~/.bashrc) that you can use to quickly commit and always include the diff. These are mine:

alias gc='git commit -v'
alias gca='git commit -v -a'

Note that the -v switch will also work when you --amend to a commit. It will always show the full diff of that commit, which is very nice.

Posted by Arne Hartherz to makandra dev (2012-08-29 19:36)