Common causes
- A branch and a file have the same name and Git can't determine which one you mean
- Using a short commit hash that matches more than one object
- Referencing HEAD or a branch name in a repo with no commits
- Using -- to separate paths but in the wrong position
How to fix it
- Use -- to explicitly separate a branch/commit from a file path: git checkout HEAD -- <file>
- Specify the full ref: git show refs/heads/<branch-name>
- Use a full commit hash instead of a short one: git show <full-40-char-hash>
- Check what the ambiguous name matches: git rev-parse <name>
Example
fatal: ambiguous argument 'main': both revision and filename
Use '--' to separate paths from revisionsRunning git diff main when a file named 'main' also exists in the working tree
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
