我在git配置中使用了以下别名来进行格式化

$ git config alias.lp '!git log --pretty=format:"%h - %an (%ar): %s"'

它用于其他别名,以下是正确的工作示例:
$ git config alias.la '!f(){ git lp -20 --author="${1-Baur}"; }; f'
$ git config alias.lm '!f(){ git lp --grep "${1-strange}"; }; f'
$ git config alias.lf '!git lp --follow'

但我找不到如何实现alias来查看上游提交的方法。
这是有效的:
$ git log --pretty=format:"%h - %an (%ar): %s" HEAD..@{u}

但这不起作用:
$ git lp HEAD..@{u}

出现错误消息:
fatal: ambiguous argument 'HEAD..@u': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

如您所见,HEAD..@{u}变成了HEAD..@u,花括号丢失。
启用$ GIT_TRACE=1后:
$ git lp HEAD..@{u}
21:17:32.678084 git.c:560               trace: exec: 'git-lp' 'HEAD..@{u}'
21:17:32.679097 run-command.c:626       trace: run_command: 'git-lp' 'HEAD..@{u}'
21:17:32.683098 run-command.c:626       trace: run_command: 'git log --pretty=format:"%h - %an (%ar): %s"' 'HEAD..@{u}'
21:17:32.726084 git.c:328               trace: built-in: git 'log' '--pretty=format:%h - %an (%ar): %s' 'HEAD..@u'
fatal: ambiguous argument 'HEAD..@u': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

我应该如何在windows上的git bash中的git lp HEAD..@{u}中转义大括号?
[更新]
感谢@phd指出linux上没有问题!
我检查了这个转义问题是否只出现在windows上的git bash上。
windows上的本地ubuntu和ubuntu没有这个问题。
但我必须使用windows版本。所以我还在寻找解决办法。
$ git --version
git version 2.14.1.windows.1

最佳答案

对我有用:

$ git --version
git version 2.11.0

$ git config alias.lp '!git log --pretty=format:"%h - %an (%ar): %s"'

$ git config alias.lp
!git log --pretty=format:"%h - %an (%ar): %s"

$ git lp HEAD~..@{u}
fc4c763 - Oleg Broytman (5 weeks ago): Build, Tests(tox): Python 3.7

$ GIT_TRACE=1 git lp @~..@{u}
15:57:15.464236 git.c:600               trace: exec: 'git-lp' '@~..@{u}'
15:57:15.464326 run-command.c:350       trace: run_command: 'git-lp' '@~..@{u}'
15:57:15.465775 run-command.c:350       trace: run_command: 'git log --pretty=format:"%h - %an (%ar): %s"' '@~..@{u}'
15:57:15.466182 run-command.c:209       trace: exec: '/bin/sh' '-c' 'git log --pretty=format:"%h - %an (%ar): %s" "$@"' 'git log --pretty=format:"%h - %an (%ar): %s"' '@~..@{u}'
15:57:15.469076 git.c:371               trace: built-in: git 'log' '--pretty=format:%h - %an (%ar): %s' '@~..@{u}'
15:57:15.471285 run-command.c:350       trace: run_command: 'less'
15:57:15.471744 run-command.c:209       trace: exec: 'less'

10-01 02:45
查看更多