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?
You need to make sure you don't have:
release/test
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With