我正在尝试使用Git Immersion的日志别名:
[alias]
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Run Code Online (Sandbox Code Playgroud)
但 Git 回应
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Run Code Online (Sandbox Code Playgroud)
使用 v1.6.1。到目前为止,我所做的只是在 master 上提交两次,然后在分支上提交一次。这个别名在其他地方对我有用,这台特定机器上可能有什么问题?
编辑 - 根据下面lesmana的建议,我能够确定在将行粘贴到 PuTTY 后,引号中的反斜杠以某种方式被剥离了。使用"而不是\".
les*_*ana 18
这是错误消息的来源:
$ git log %ad
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Run Code Online (Sandbox Code Playgroud)
您将从以下两个命令中获得相同的错误消息:
$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
$ git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Run Code Online (Sandbox Code Playgroud)
问题是git log接收以下两个参数:--pretty=format:%h(or --pretty=format:\"%h) 和%ad. 其余的,至少当在 bash 中直接作为命令执行时,是到 command 的管道%s%d,通常不存在。因此,我系统上的完整错误消息如下所示:
$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
bash: %s%d: command not found
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Run Code Online (Sandbox Code Playgroud)
所有这些都表明引用不知何故丢失并被%ad解释为 git log 的参数。为防止出现这种情况,您必须找到正确的引用和转义组合,以便在执行时正确引用格式字符串。
关于别名和引用的 git config手册:
参数由空格分隔,支持通常的 shell 引用和转义。引用对和反斜杠可用于引用它们。
从这一行我无法弄清楚引用和转义是如何工作的。我尝试了在别名中引用和转义的某种组合,但无法从中得到任何意义。
您在问题中发布的以下几行在我的系统上运行良好:
[alias]
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Run Code Online (Sandbox Code Playgroud)
在使用 PuTTY 和所有工具时,您必须尝试在您的系统上获得正确的组合。
| 归档时间: |
|
| 查看次数: |
10893 次 |
| 最近记录: |