![](/img/trans.png)
[英]Is it possible to use the `master^{tree}` syntax of `git cat-file -p` to print blobs?
[英]git cat-file -p master^{tree} errors out in zsh
在gitscm.org文档中,在git objects章节下,它使用下面的命令,但尝试它会给我“zsh:找不到匹配项:master^{tree}”。 知道什么是不正确的吗?
git cat-file -p master^{tree}
我发现在指定那些更棘手的 git 修订参数时,我必须引用它们
git cat-file -p "master^{tree}"
同时省略"
失败。
这种行为及其原因因平台而异:
^
字符用于转义。 因此,作为替代方案,您可以编写git cat-file -p master^^{tree}
^
字符用于通配符(感谢 Wumpus Q. Wumbley 和 kostix 的解释)
如果你想在没有通配符的情况下运行whatever
东西,你可以运行noglob whatever
东西。 例如,我将它定义为rake
的别名。
在 Windows 中执行该步骤之前需要克隆项目。
此错误的各种可能情况:
根据您使用的 shell,您在使用 master^{tree} 语法时可能会遇到错误。
在 Windows 上的 CMD 中,^ 字符用于转义,因此您必须将其加倍以避免这种情况:git cat-file -p master^^{tree}。 使用 PowerShell 时,必须引用使用 {} 字符的参数以避免参数被错误解析:git cat-file -p 'master^{tree}'。
如果您使用 ZSH,^ 字符用于通配符,因此您必须将整个表达式括在引号中:git cat-file -p "master^{tree}"。
正如 villasv 指出的那样:“如果你得到“不是一个有效的对象名 master^{tree}”,请确保你至少完成了一次提交。在 git init 之后,master 分支还不存在。-villasv”因为master^{tree} 语法将 master 分支上的最后一次提交所指向的树对象指定为git 对象在提交到当前更改后, git cat-file -p 'master^{tree}'
可以是执行。
根据您使用的 shell,您在使用 master^{tree} 语法时可能会遇到错误。
在 Windows 上的 CMD 中,^ 字符用于转义,因此您必须将其加倍以避免这种情况:git cat-file -p master^^{tree}。 使用 PowerShell 时,必须引用使用 {} 字符的参数以避免参数被错误解析:git cat-file -p 'master^{tree}'。
如果您使用 ZSH,^ 字符用于通配符,因此您必须将整个表达式括在引号中:git cat-file -p "master^{tree}"。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.