How to fix fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 339 views

This error occurs when Git cannot resolve a reference like HEAD~ because the repository has no commits, only one commit (no parent exists), or the reference is otherwise invalid. It commonly appears when trying to undo commits in a new repository.

Quick fix

Fixes fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree

git log --oneline
  1. Check your commit history
  2. Verify HEAD exists and is valid
  3. Undo the initial commit (if that's your goal)
  4. Fetch full history for shallow clones
git โ€” error
git log --oneline
fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree

What this error means

The "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree" error means Git cannot find the commit you're trying to reference. HEAD~ (or HEAD~1) refers to the parent commit of your current HEAD position. This error typically occurs in three scenarios: 1. **New repository with no commits**: In a freshly initialized repository with no commits, HEAD doesn't point to anything valid yet. 2. **Initial commit with no parent**: If your repository only has one commit (the initial commit), there is no parent commit to reference. HEAD~ asks for the commit before the current one, but the first commit has no predecessor. 3. **Shallow clone**: If you cloned with `--depth=1`, Git only fetched the most recent commit, so parent commits may not exist locally. This is a common issue when using VSCode's "Undo Last Commit" feature or running `git reset HEAD~` after making only one commit.

Typical symptoms

  • Running 'git reset HEAD~' fails with 'ambiguous argument' error
  • VSCode 'Undo Last Commit' shows error after first commit
  • Git commands referencing HEAD~ or HEAD~1 fail unexpectedly
  • 'git diff HEAD~' fails in a repository with few commits
  • CI/CD pipeline fails on git history commands in shallow clones
  • Cannot undo the initial commit using standard reset commands

Common causes

  1. Attempting to reference a parent commit when only one commit exists (initial commit has no parent)
  2. Running git commands in a newly initialized repository with no commits yet
  3. Working in a shallow clone where parent commits weren't fetched
  4. HEAD is detached and pointing to an invalid or orphaned reference
  5. Repository corruption or missing objects in .git directory
  6. Using HEAD~ in scripts that run before any commits are made

How to fix "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree"

1Check your commit history

First, verify how many commits exist in your repository:

bash
git log --oneline

If this shows only one commit or fails entirely, that confirms you're trying to reference a non-existent parent commit.

2Verify HEAD exists and is valid

Check if HEAD points to a valid commit:

bash
git rev-parse HEAD

If this fails with "unknown revision or path not in the working tree", your repository has no commits yet. Make an initial commit first:

bash
git add .
git commit -m "Initial commit"
3Undo the initial commit (if that's your goal)

To undo the very first commit while keeping your files, use git update-ref:

bash
git update-ref -d HEAD

This deletes the HEAD reference, effectively reverting to a state before the initial commit. Your staged files remain in the index. To also unstage files:

bash
git update-ref -d HEAD
git reset
4Fetch full history for shallow clones

If you're working with a shallow clone, fetch the complete history:

bash
# Fetch all history
git fetch --unshallow

# Or fetch a specific depth
git fetch --depth=100

After this, parent commit references should work correctly.

5Use alternative methods to modify history

For the initial commit, consider these alternatives:

Amend instead of reset:

bash
git commit --amend -m "New message"

Create an orphan branch to start fresh:

bash
git checkout --orphan new-start
git add .
git commit -m "Fresh start"
git branch -D main  # Delete old branch
git branch -m main  # Rename current branch
6Handle in scripts and CI/CD pipelines

In automated scripts, check commit count before using HEAD~:

bash
# Check if there are at least 2 commits
if [ $(git rev-list --count HEAD) -gt 1 ]; then
  git diff HEAD~
else
  echo "Not enough commits for HEAD~ reference"
fi

For CI/CD, ensure you're not using a shallow clone if you need history:

yaml
# GitHub Actions example
- uses: actions/checkout@v4
  with:
    fetch-depth: 0  # Fetch all history

Advanced notes

Understanding Git references: HEAD~ is shorthand for HEAD~1, meaning "the first parent of HEAD." HEAD~2 means "the grandparent of HEAD." These only work when those ancestors exist.

Orphan branches: An orphan branch has no commit history. Creating one is useful when you want a completely fresh start without deleting the repository:

bash
git checkout --orphan fresh-branch

The difference between HEAD~ and HEAD^: Both reference parent commits, but they differ for merge commits. HEAD~ always follows the first parent, while HEAD^ can specify which parent (HEAD^2 for second parent in a merge).

Repository integrity: If you suspect corruption, run git fsck to check for missing or corrupt objects. Missing commits may cause reference errors even in repositories with valid history.

Interactive rebase limitations: Like reset, interactive rebase (git rebase -i HEAD~N) requires N ancestor commits to exist. For the initial commit, use git rebase -i --root instead.

Frequently asked questions

What does "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the" mean?
The "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree" error means Git cannot find the commit you're trying to reference. HEAD~ (or HEAD~1) refers to the parent commit of your current HEAD position. This error typically occurs in three scenarios: 1.
How do I fix "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the"?
This error occurs when Git cannot resolve a reference like HEAD~ because the repository has no commits, only one commit (no parent exists), or the reference is otherwise invalid. It commonly appears when trying to undo commits in a new repository.
What causes "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the"?
Attempting to reference a parent commit when only one commit exists (initial commit has no parent) Running git commands in a newly initialized repository with no commits yet Working in a shallow clone where parent commits weren't fetched
Is the "fatal: ambiguous argument 'HEAD~': unknown revision or path not in the" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading