`git commit -v` 默认情况下

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5875275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:24:30  来源:igfitidea点击:

`git commit -v` by default

git

提问by Kevin Reid

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

默认情况下,如何配置git commitgit commit -v(显示正在提交的完整差异)?

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.

使用别名不是很令人满意,因为它不会影响可能间接提交的操作期间的提交消息编辑,例如git rebase.

采纳答案by Cheng Kai

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

如果您使用的是 git 2.9,这可以通过配置来完成。

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 2.9.0 发行说明: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.

“git commit”学会了注意“commit.verbose”配置变量,并且就像从命令行给出“--verbose”选项一样。

回答by asmeurer

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

据我所知,您不能用别名覆盖已经存在的 git 命令(否则,将无法执行原始命令,并且一堆东西会中断)。

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

所以我建议你做类似的事情git config --global "alias.ci" "commit -v"。这将行添加到您的~/.gitconfig文件,并让这个git cigit commit -v。然后,您应该养成键入git ci而不是git commit(除非您决定不想要-v)的习惯。

回答by asmeurer

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.

我相信有很多像这样的漂亮别名是我从 PeepCode git 截屏视频中得到的。

回答by boshvark

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:

我知道这是一个老问题,但我碰巧遇到了它并有答案。我将以下函数放在 .bash_profile 中:

#!/bin/bash                                                                            

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

This turns gitinto a bash function that transforms git commitinto git commit -vand leaves the rest of the arguments mostly alone. However, it breaks git commitarguments that have whitespace, and it won't let you commit a file named cior commit.

这变成git了一个 bash 函数,它转换git commitgit commit -v并留下其余的参数,大部分都是单独的。但是,它会破坏git commit具有空格的参数,并且不会让您提交名为ci或的文件commit

回答by d33tah

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

我刚刚发送了一封电子邮件,[email protected]并收到了以下回复:

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

05.04.2016 16:47,Pranit Bauva:2016 年 4 月 5 日星期二晚上 8:08,Jacek Wielemborek 写道:

你好,

我要求这个是因为有很多人(包括我在内)对此功能感兴趣,并且没有方便的解决方法:

`git commit -v` 默认情况下

干杯,d33tah

这是目前正在进行中。我就是那个正在努力的人。其中一个补丁目前在 pu 分支上。我仍在完善它以包含更多内容。您可以通过 git 维护者阅读 git.git 消息来跟踪其状态。该补丁的最新版本位于http://thread.gmane.org/gmane.comp.version-control.git/288820

谢谢,Pranit Bauva

回答by alxndr

Silly workaround: :!git log -1 -u

愚蠢的解决方法: :!git log -1 -u

回答by Armand

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

以下放入.bashrc/.profile似乎可以完成这项工作:

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