Home > Enterprise >  fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree when u
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree when u

Time:01-13

I am trying to take out git diff of a particular file in a folder using below command on azure devops pipeline:

git diff --name-only HEAD^ .\dev-artifacts.properties .\dev-artifacts.properties

or

git diff --name-status HEAD HEAD^

or

git diff --name-only dev-artifacts.properties dev-artifacts.properties

After running this command, I am getting below error:

fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'

I tried switching the branch (main branch), but still it is not working. But in my local I am able to get the difference using git diff.

I want to get the difference using git diff, so that I can run a python script when there is a change in file.

CodePudding user response:

You have a shallow repository with only a single commit. You can verify by executing git rev-parse --is-shallow-repository.

HEAD^ points to the commit before your current commit – which does not exist in shallow clones of depth 1. You have to unshallow your clone or deepen it to include the commits which you are referencing.

For instance, to deepen your shallow clone to include the latest 5 commits, run git fetch --depth=5

  •  Tags:  
  • git
  • Related