Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff gives ambigious argument error

Tags:

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
like image 365
am28 Avatar asked Oct 15 '15 15:10

am28


People also ask

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.

What does git diff do?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How do I get out of git diff staged?

To exit this you can use: :q for exit; :h for help; Note: if you don't want to read the output in pager you can use an ENV variable GIT_PAGER to cat or you need to set core.

What does git diff -- staged tell you why is this blank?

git diff --staged shows you the difference between your staging area and the last commit to the repository. git commit commits all changes in the staging area and opens Vim so you can add a commit message.


1 Answers

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
like image 63
idjaw Avatar answered Oct 22 '22 02:10

idjaw