Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff fatal: ambiguous argument unknown revision or path not in working tree

I am running git fetch origin in my production code and then am trying to a Git diff with my current branch with origin/master. I am facing this error while running the command:

fatal: ambiguous argument unknown revision or path not in working tree

Please find below the command used and the actual error.

Command tried:

git fetch origin
git diff --name only release/test origin/master

Expected output:

git diff should work

Actual output:

[localhost] local: git diff --name-only release/test origin/master |   ambiguous argument 'release/test': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

How can we correct the issue with my Git diff command?

like image 332
Manigandan Thanigai Arasu Avatar asked Oct 28 '22 20:10

Manigandan Thanigai Arasu


2 Answers

You need to make sure you don't have:

  • Either a path within your Git repository folder which would match the branch name, that is a folder release/test
  • or, as noted by philant, a branch name matching the path of the file being diffed,
  • or a tag matching the branch name: git tag -l (Listing release/test)

Adding -- would make sure the two branch names are interpreted as literals, not options. In this case (git diff), as paths, not commits or other git diff options.

git diff --name-only release/test origin/master --

In your case, this should fail unless you actually have paths/folders named release/test and origin/master.

So git diff [<options>] <commit> <commit> remains the correct syntax.
You only need to make sure there is no path or tag already named like one of those two commits.

like image 182
VonC Avatar answered Nov 16 '22 15:11

VonC


The solution was first to checkout the branch, and then git diff commands would work.

$ git diff --name-only master...release/v1.1

fatal: ambiguous argument 'master...release/v1.1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


$ git diff --name-only master release/v1.1 --

fatal: bad revision 'release/v1.1'


$ git checkout release/v1.1

Switched to a new branch 'release/v1.1'
Branch 'release/v1.1' set up to track remote branch 'release/v1.1' from 'origin'.


$ git diff --name-only master release/v1.1

foo
bar
like image 37
aland Avatar answered Nov 16 '22 15:11

aland