![](/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.