1

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

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 日志?

4

1 回答 1

3

如果在 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 置于更适合本机可执行文件的不同解析模式。有关更多详细信息,请参阅此博客文章

如果您不使用 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,那么您就有机会弄清楚如何处理通常涉及使用额外引号的参数。

于 2012-12-31T18:46:33.263 回答