am28
am28

Reputation: 381

git diff gives ambigious argument error

I recently moved from SVN to git, and trying to learn my way around git. I need to find the files that have changed between 2 branches of my repository. I use the following command to that:

git diff branch_2..branch_1

I get the follwing error:

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

git branch gives the following o/p:

git branch -a
* branch_1
master/origin
remotes/origin/HEAD -> origin/master
remotes/origin/branch_2
remotes/origin/branch_1

Upvotes: 27

Views: 28552

Answers (2)

Gen.Stack
Gen.Stack

Reputation: 246

Sometimes you got a shallow git repo, created using

git clone --depth 1 <repo-url>

Trying to git diff fails w/ a fatal: ambiguous argument error:

fatal: ambiguous argument [...]: unknown revision or path not in the working tree.

You then need to make your refs locally available. Convert a shallow git repo to a full (unshallow) repo from a shallow one, see git deep fetch and git unshallow.

Then it should be able to git diff branches:

git diff branch1

Aforementioned example compares branch1 to the active working branch.

HTH

Upvotes: 6

idjaw
idjaw

Reputation: 26578

If you are simply doing:

git diff branch2..branch1

This will not work, as listed in your git branch list, your 'remotes' are specified as "origin". What this actually means is that you have those branches on your remote, but they aren't actually checked out locally.

So you have two options here. Try these, and let me know how it goes.

Based on the branch list provided:

Diff using origin/

git diff origin/branch2..branch1

If you want to checkout these branches locally to perform your diff and maybe work on them on your workstation. Furthermore, supporting the diff in this format:

git diff branch2..branch1

What you need to do is actually checkout those branches to set them as local branches from your remote. Simply do this:

git checkout branch2

Then you can do

git diff branch2..branch1

Upvotes: 29

Related Questions