`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
`git commit -v` by default
提问by Kevin Reid
How can I configure git commit
to act as git commit -v
(showing the full diff being committed) by default?
默认情况下,如何配置git commit
为git 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 ~/.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
).
所以我建议你做类似的事情git config --global "alias.ci" "commit -v"
。这将行添加到您的~/.gitconfig
文件,并让这个git ci
做git 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 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
.
这变成git
了一个 bash 函数,它转换git commit
成git 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:
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 写道:
你好,
我要求这个是因为有很多人(包括我在内)对此功能感兴趣,并且没有方便的解决方法:
干杯,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
/.profile
seems to do the job:
以下放入.bashrc
/.profile
似乎可以完成这项工作:
git() {
if [[ "" = "commit" ]]; then
shift
command git commit -v "$@"
else
command git "$@"
fi
}