Git: When committing, check the diff

Updated . Posted . Visible to the public.

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.

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.

Arne Hartherz
Last edit
Attachments
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2012-08-29 17:36)