test.txt %h%ad%an%s" $out > test.txt --% 将 PowerShell 置-6ren">
gpt4 book ai didi

powershell - 在 Powershell 中转义以获取 git log

转载 作者:行者123 更新时间:2023-12-03 01:20:52 25 4
gpt4 key购买 nike

我知道转义字符是 (`),即反引号,但即使我尝试使用它来转义 < 字符,我也会收到错误...

git log ORIG_HEAD --no-merges --date=short --pretty="format:<tr><td>%h</td><td>%ad</td><td>%an</td><td>%s</td></tr>" > test.txt
< was unexpected at this time.

我怎样才能像上面那样格式化我的 git 日志?

最佳答案

如果在 PowerShell v3 上试试这个:

$out = git log ORIG_HEAD --% --no-merges --date=short --pretty="format:<tr><td>%h</td><td>%ad</td><td>%an</td><td>%s</td></tr>"
$out > test.txt

--% 将 PowerShell 置于更适合 native 可执行文件的不同解析模式。看到这个 blog post更多细节。

如果您不使用 PowerShell v3,我建议您使用 PowerShell Community Extensions 中的 echoargs在 git.exe 从 PowerShell 接收参数时查看参数,例如:
PS> echoargs log ORIG_HEAD --no-merges --date=short --pretty="format:<tr><td>%h</td><td>%ad</td><td>%an</td><td>%s</td></tr>"
Arg 0 is <log>
Arg 1 is <ORIG_HEAD>
Arg 2 is <--no-merges>
Arg 3 is <--date=short>
Arg 4 is <--pretty=format:<tr><td>%h</td><td>%ad</td><td>%an</td><td>%s</td></tr>>

Command line:
"C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe" log ORIG_HEAD --no-merges --date=short --pretty=format:<tr><td>%h</td><td>%ad</td><td>%an</td><td>%s</td></tr>

如果您可以看到 PowerShell 如何将参数传递给 exe,那么您就有机会弄清楚如何处理通常涉及使用额外引号的参数。

关于powershell - 在 Powershell 中转义以获取 git log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14104998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com