在Powershell中转义为git日志

时间:2012-12-31 18:34:02

标签: powershell git-log

我知道转义字符是(`),反引号,但即使我试图用它来逃避<我得到错误的字符......

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

1 个答案:

答案 0 :(得分: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置于更适合本机可执行文件的不同解析模式。有关详细信息,请参阅此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,你就有机会弄清楚如何按摩通常涉及使用额外引号的参数。