在命令上设置 git 默认标志 [英] Setting git default flags on commands
问题描述
我想知道是否有办法为 git 命令默认设置标志.具体来说,我想设置 --abbrev-commit
标志,以便在执行 git log
时,我想执行 git log --abbrev-commit代码>.
I want to know if there is a way to set a flag by default for git command. Specifically, I want to set the --abbrev-commit
flag so that when executing git log
, I want to execute git log --abbrev-commit
.
不同于问题有没有办法在默认情况下为 git 命令设置标志?",显然没有将 --abbrev-commit 添加到 git log 的配置标志.此外,git 手册指出我不能创建别名:为了避免脚本使用的混乱和麻烦,隐藏现有 git 命令的别名将被忽略"
Unlike the question "is there any way to set a flag by default for a git command?", there is apparently not a configuration flag for adding --abbrev-commit to git log. Furthermore, the git manual states that I cannot create an alias: "To avoid confusion and troubles with script usage, aliases that hide existing git commands are ignored"
我的第三个选择是在我的 .gitconfig 文件中创建一个像 glog=log --abbrev-commit
这样的新别名.但我宁愿不使用新命令发明我自己的 DSL.
My third option is to invent a new alias like glog=log --abbrev-commit
in my .gitconfig file. But I'd rather not invent my own DSL with new commands.
是否有另一种方法来实现它,以便默认设置 abbrev-commit
标志??
Is there another way to achieve it so that the abbrev-commit
flag is set by default??
推荐答案
从 git 1.7.6 版本开始,git config 获得了一个 log.abbrevCommit 选项,可以设置为 true.因此,答案是至少升级到 1.7.6(在撰写本文时当前为 1.7.11.4)并使用:
Since git version 1.7.6, git config has gained a log.abbrevCommit option which can be set to true. Thus the answer is upgrade to at least 1.7.6 (current as of this writing is 1.7.11.4) and use:
git config --global log.abbrevCommit true
这篇关于在命令上设置 git 默认标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!