Justin808
Justin808

Reputation: 21512

Escaping in Powershell for a git log

I know the escape character is (`), the backtick, but even if I try to use it toe escape the < characters I get error...

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.

How can I go about formatting my git log as above?

Upvotes: 1

Views: 932

Answers (1)

Keith Hill
Keith Hill

Reputation: 201632

If on PowerShell v3 try this:

$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

The --% puts PowerShell into a different parsing mode more suitable for native executables. See this blog post for more details.

If you're not using PowerShell v3, I suggest you use echoargs from the PowerShell Community Extensions to see the arguments as git.exe receives them from PowerShell e.g.:

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>

If you can see how PowerShell is passing the arguments to the exe you have a fighting chance to figure out how to massage the arguments which usually involves using extra quotes.

Upvotes: 3

Related Questions