Skip to content

Welcome to Tech by Example

Menu
  • Home
  • Posts
  • System Design Questions
Menu

zsh: no matches found: HEAD^

Posted on October 11, 2022October 11, 2022 by admin

Overview

^ character is a special character in filename expansion in zsh. There are a couple of ways to fix it

Workaround 1

Escape the ^ character

Eg

git reset HEAD\^ --soft

or use quotes

git reset 'HEAD^' --soft

Workaround 2 (Permanent Fix)

It happens because of EXTENDED_GLOB option due to which zsh allow ^ to negate blobs. As quoted here

https://zsh.sourceforge.io/Doc/Release/Options.html

EXTENDED_GLOB

Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename generation, etc. (An initial unquoted ‘~’ always produces named directory expansion.)

So simply unsetopt this option in the terminal

unsetopt EXTENDED_GLOB
git reset HEAD\^ --soft

To fix it permanently, you can write this line on your .zshrc file. This tells .zsh to not print an error when pattern matching fails and to use the command as is

unsetopt NOMATCH

PS: It is not a good idea to unsetopt EXTENDED_GLOB in .zshrc otherwise you won’t be able to use that behavior. With NOMATCH turned off it is not simply printing the error when pattern matching fails

A description of NOMATCH can be found here

https://zsh.sourceforge.io/Doc/Release/Options.html

NOMATCH (+3) <C> <Z>

If a pattern for filename generation has no matches, print an error, instead of leaving it unchanged in the argument list. This also applies to file expansion of an initial ‘~’ or ‘=’.

Note: Check out our system design tutorial series System Design Questions

©2025 Welcome to Tech by Example | Design: Newspaperly WordPress Theme