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

Time:01-24

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

What's happening?

CodePudding user response:

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.

  • Related