Question

I am getting some weird output on trying to do diff between HEAD and last commit

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>...]'

While using git diff <sha> HEAD^, I get the error

warning: ignoring dangling symref head. warning: ignoring dangling symref head.
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>...]'

am I missing something?

Was it helpful?

Solution

Okay, I think there can be 2 possible reasons here

1) Issue here is, you are trying to do a git diff <sha> head^

In this case, you need to correct your command to git diff <sha> HEAD^. Note the upper case characters. Check out this question to read more about HEAD.

2) You are trying git diff <sha> HEAD^ and are still getting the error message. In this case, I think you have only one commit in your repository. While the sha points to that lone commit, your HEAD also happens to point at that first commit, and HEAD^ happens to point at the commit before that, which doesn't exist, so the error.

Another possibility here is that someone upstream has created a dangling symref (a dangling object) while doing a merge or a git reset or a git rebase. This should be removable by doing a git prune.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top