6

I issued the command: git reset HEAD@{2} and got an error: unknown switch `e'.

What's happening?

jmoreno
  • 12,752
  • 4
  • 60
  • 91

1 Answers1

11

In PowerShell, unlike in cmd.exe, @ and { / } are metacharacters that either require individual escaping with ` (the so-called backtick) or enclosing the entire argument in quotes:

Therefore:

# Metacharacter-individual escaping
git reset HEAD`@`{2`} 

# Enclosing the whole argument in quotes
git reset 'HEAD@{2}' 

Note:


As for the obscure error message you saw:

  • Unescaped use of {...} causes the latter to be interpreted as a script block.

  • Due to a bug, still present as of PowerShell 7.3.1, the presence of a script block inappropriately triggers translation of such an argument to a Base64-encoded argument passed to an -encodedCommand parameter, which is only meaningful when calling the PowerShell CLI (powershell.exe for Windows PowerShell, pwsh for PowerShell (Core) 7+) - see GitHub issue #10842.

  • git therefore sees -encodedCommand on its command line, and complains about not knowing option -e.

mklement0
  • 382,024
  • 64
  • 607
  • 775