简体   繁体   English

zsh 中的 git cat-file -p master^{tree} 错误

[英]git cat-file -p master^{tree} errors out in zsh

In gitscm.org documentation, under git objects chapter, it uses the command below, but trying it out gives me "zsh: no matches found: master^{tree}".gitscm.org文档中,在git objects章节下,它使用下面的命令,但尝试它会给我“zsh:找不到匹配项:master^{tree}”。 Any idea what's incorrect?知道什么是不正确的吗?

git cat-file -p master^{tree}

I've found that when specifying those more tricky git revision parameters, I have to quote them我发现在指定那些更棘手的 git 修订参数时,我必须引用它们

git cat-file -p "master^{tree}"

while leaving out the " fails.同时省略"失败。

This behavior and and the reason for it varies with the platform:这种行为及其原因因平台而异:

  • On Windows, in PowerShell and cmd.exe, the ^ character is used for escaping.在 Windows 上,在 PowerShell 和 cmd.exe 中, ^字符用于转义。 So, as an alternative, you can write git cat-file -p master^^{tree}因此,作为替代方案,您可以编写git cat-file -p master^^{tree}
  • In zsh the ^ character is used for globbing在 zsh 中, ^字符用于通配符
  • In bash the command works without quotes在 bash 中,该命令不带引号

(thanks to Wumpus Q. Wumbley and kostix for explanations) (感谢 Wumpus Q. Wumbley 和 kostix 的解释)

You can run noglob whatever if you want to run whatever without globbing.如果你想在没有通配符的情况下运行whatever东西,你可以运行noglob whatever东西。 I have it defined as an alias for rake , for instance.例如,我将它定义为rake的别名。

在 Windows 中执行该步骤之前需要克隆项目。

The various possible cases for this error:此错误的各种可能情况:

Depending on what shell you use, you may encounter errors when using the master^{tree} syntax.根据您使用的 shell,您在使用 master^{tree} 语法时可能会遇到错误。

In CMD on Windows, the ^ character is used for escaping, so you have to double it to avoid this: git cat-file -p master^^{tree}.在 Windows 上的 CMD 中,^ 字符用于转义,因此您必须将其加倍以避免这种情况:git cat-file -p master^^{tree}。 When using PowerShell, parameters using {} characters have to be quoted to avoid the parameter being parsed incorrectly: git cat-file -p 'master^{tree}'.使用 PowerShell 时,必须引用使用 {} 字符的参数以避免参数被错误解析:git cat-file -p 'master^{tree}'。

If you're using ZSH, the ^ character is used for globbing, so you have to enclose the whole expression in quotes: git cat-file -p "master^{tree}".如果您使用 ZSH,^ 字符用于通配符,因此您必须将整个表达式括在引号中:git cat-file -p "master^{tree}"。

As villasv pointed out that: " If you do get "Not a valid object name master^{tree}", make sure you have at least one commit done. The master branch does not exist yet immediately after git init. – villasv " Since The master^{tree} syntax specifies the tree object that is pointed to by the last commit on your master branch as referenced to git object After making commit to current change, git cat-file -p 'master^{tree}' can be executed.正如 villasv 指出的那样:“如果你得到“不是一个有效的对象名 master^{tree}”,请确保你至少完成了一次提交。在 git init 之后,master 分支还不存在。-villasv”因为master^{tree} 语法将 master 分支上的最后一次提交所指向的树对象指定为git 对象在提交到当前更改后, git cat-file -p 'master^{tree}'可以是执行。

Depending on what shell you use, you may encounter errors when using the master^{tree} syntax.根据您使用的 shell,您在使用 master^{tree} 语法时可能会遇到错误。

In CMD on Windows, the ^ character is used for escaping, so you have to double it to avoid this: git cat-file -p master^^{tree}.在 Windows 上的 CMD 中,^ 字符用于转义,因此您必须将其加倍以避免这种情况:git cat-file -p master^^{tree}。 When using PowerShell, parameters using {} characters have to be quoted to avoid the parameter being parsed incorrectly: git cat-file -p 'master^{tree}'.使用 PowerShell 时,必须引用使用 {} 字符的参数以避免参数被错误解析:git cat-file -p 'master^{tree}'。

If you're using ZSH, the ^ character is used for globbing, so you have to enclose the whole expression in quotes: git cat-file -p "master^{tree}".如果您使用 ZSH,^ 字符用于通配符,因此您必须将整个表达式括在引号中:git cat-file -p "master^{tree}"。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM