如何通过 ssh 设置带有引号的复杂 git 配置?

问题描述 投票:0回答:1

% ssh me@my-vm "git config --global alias.l 'log --graph --all --pretty=format:"%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset"'" 

zsh: no matches found: git config --global alias.l 'log --graph --all --pretty=format:%C(yellow)%h%C(cyan)%d%Creset 

我不知道为什么会发生这个 zsh 错误。

另一方面,采用更简单的 git 配置

% ssh me@my-vm "git config --global user.name 'First Last'"

Warning: Permanently added 'my-vm' (ED25519) to the list of known hosts.

工作完美。这让我相信问题不是我试图设置 git config 而是我试图设置的别名的复杂性,但我只是不知道错误试图告诉我什么。

git ssh
1个回答
0
投票

单引号不保护格式周围的双引号;紧接着

"
format:
关闭当前字符串,就好像单引号不存在一样。您需要转义要作为 shell 命令的一部分发送到远程主机的
"

ssh me@my-vm "git config --global alias.l 'log --graph --all --pretty=format:\"%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset\"'" 
© www.soinside.com 2019 - 2024. All rights reserved.