Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git reset HEAD@{n} results in error "unknown switch 'e'"

Tags:

git

powershell

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

What's happening?

like image 530
jmoreno Avatar asked Sep 08 '25 03:09

jmoreno


1 Answers

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:

  • Strictly speaking , @ is only a metacharacter at the start of an argument.

  • The above uses a verbatim (single-quoted) string ('...'); if string expansion (interpolation) is needed, use an expandable (double-quoted) string ("...")

  • For a list of all of PowerShell's metacharacters in argument[-parsing] mode, see this answer.


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.

like image 102
mklement0 Avatar answered Sep 09 '25 15:09

mklement0