开发者

`git commit -v` by default

开发者 https://www.devze.com 2023-03-03 03:34 出处:网络
How can I configure git commit to act as git commit -v (showing the full diff being committed) by default?

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.


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.


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).


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.


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.


I just sent an e-mail to git@vger.kernel.org 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


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
}


Silly workaround: :!git log -1 -u

0

精彩评论

暂无评论...
验证码 换一张
取 消