8

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
aland
  • 1,824
  • 2
  • 26
  • 43
  • 1
    It looks like that worked because you didn't have a local copy of release/v1.1. Another option would have been to use "origin/release/v1.1" – Poco Aug 30 '23 at 17:04