73
votes

How can I configure git commit to act as git commit -v (showing the full diff being committed) by default?

Using an alias is not quite satisfactory, as it does not affect commit message editing during operations which may indirectly commit, such as git rebase.

7

7 Answers

68
votes

If you are using git 2.9, this can be done with a config.

git config --global commit.verbose true

Git 2.9.0 Release Notes: https://github.com/git/git/blob/v2.9.0/Documentation/RelNotes/2.9.0.txt

"git commit" learned to pay attention to the "commit.verbose" configuration variable and act as if the "--verbose" option was given from the command line.

30
votes

As far as I can tell, you can not override an already existing git command with an alias (otherwise, there would be no way to do the original command, and a bunch of stuff would break).

So I recommend you do something like git config --global "alias.ci" "commit -v". This will add a line to your ~/.gitconfig file and make it so that git ci does git commit -v. You should then just get into the habit of typing git ci instead of git commit (unless you decide you don't want the -v).

9
votes

Well, I use aliases:

alias gc='git commit -v'

There are a bunch of nice aliases like this that I got off the PeepCode git screencasts, I believe.

6
votes

I know this is an old question, but I happened to come across it and have an answer. I put the following function in .bash_profile:

#!/bin/bash                                                                            

git()                                                                                  
{                                                                                      
    case "$1" in                                                                       
        ci|commit)
        gitargs=""
        for i in $@; do
            if [ "$1" != "$i" ]; then                                                  
                gitargs="$gitargs $i"
            fi  
        done
        command git commit -v $gitargs
        ;;  
    *)  
        command git "$@"
        ;;                                                                             
    esac                                                                               
}

This turns git into a bash function that transforms git commit into git commit -v and leaves the rest of the arguments mostly alone. However, it breaks git commit arguments that have whitespace, and it won't let you commit a file named ci or commit.

4
votes

I just sent an e-mail to [email protected] and got the following response:

05.04.2016 16:47, Pranit Bauva: On Tue, Apr 5, 2016 at 8:08 PM, Jacek Wielemborek wrote:

Hello,

I'm asking for this one because there's quite a lot of interest (including me) in this feature and there is no convenient walkaround:

`git commit -v` by default

Cheers, d33tah

This is currently under progress. I am the one who is working on it. One of the patches is currently on the pu branch. I am still polishing it to include some more stuff. You can track its status by reading the git.git messages by the git maintainer. The latest revision of the patch is at http://thread.gmane.org/gmane.comp.version-control.git/288820

Thanks, Pranit Bauva

1
votes

Silly workaround: :!git log -1 -u

1
votes

The following put in .bashrc/.profile seems to do the job:

git() {
    if [[ "$1" = "commit" ]]; then
        shift
        command git commit -v "$@"
    else
        command git "$@"
    fi
}