执行Git别名时显示完整命令?

joh*_*n2x 10 git git-config

使用别名时是否有显示完整命令的选项?

例:

$ git ci -m "initial commit"
Full command: git commit -m "initial commit"
...
$ git lg
Full command: git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
...
Run Code Online (Sandbox Code Playgroud)

别名非常方便,但我喜欢学习/提醒我的别名实际上做了什么(我的大部分别名是从互联网上复制的)

Pet*_*oes 2

举个例子:

log-1 = "!sh -c 'echo \"Full command: git log --graph --decorate --pretty=oneline --abbrev-commit\"; git log --graph --decorate --pretty=oneline --abbrev-commit' -"

您调用 shell 并执行给定的命令。

在您的 lg 示例中,您必须进行大量转义,因为 qoutes 内有引号和需要转义的字符。我建议您创建自己的漂亮格式并在别名中使用它。假设我们将您的格式称为我的格式。这是你需要做的:

git config --add pretty.mine "%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset"

别名是

lg = "!sh -c 'echo \"Full command: git log --graph --pretty=mine --abbrev-commit --date=relative\"; git log --graph --pretty=mine --abbrev-commit --date=relative' -"