Home > Net >  Git 2.34.1: error "fatal: ambiguous argument 'HEAD': unknown" when committing in
Git 2.34.1: error "fatal: ambiguous argument 'HEAD': unknown" when committing in

Time:12-02

$ bash --noprofile                                                                                                                                                                                                                                                                  

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

bash-3.2$ git --version
git version 2.34.1


bash-3.2$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   readme.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    tmp/

bash-3.2$ git commit -m 'initial'
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

bash-3.2$ which omz # checking for oh-my-zsh

bash-3.2$ git rev-parse # no errors, so that's not it 

bash-3.2$  

I've been knocking my head against this one for a bit now so it's time to ask for help.

Git was working fine until yesterday, but I haven't done a commit in an empty repo for a few weeks. Tried upgrading git. I get the same error with/without zsh and oh-my-zsh. This similar question, well the top answer is about 9 years old and didn't help. Commit with --allow-empty caused the same error. The other answers in there didn't help either.

OSX 10.15.7

CodePudding user response:

it sounds like a faulty git hook is firing which is referencing git diff HEAD or some sort (probably instead meaning to use git diff --staged --name-only)

make sure to check .git/hooks/* (probably .git/hooks/pre-commit) or if you've configured a global hook path also check the value of git config core.hooksPath

Get your hooks path:

git config --global core.hooksPath

Check for git rev-parse in any of the hooks there, especially prepare-commit-msg.

  • Related