Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git error "fatal: bad revision" when using git diff

Tags:

git

I am trying to show changes between the origin of a certain folder and I would like it to show only the names of those that were added and modified using the following command but it is returning an error.

Command:

git diff --name-only --relative --diff-filter AM origin -- foldername/

Error:

fatal: bad revision 'origin'

Why did that suddenly happen? How can I resolve it?

Edit

using a different repo and 'origin/master' only returns different results

C:\gitprojects\samplefolder (master -> origin)
λ git diff --name-only --relative --diff-filter AM origin/master
readme.md

C:\gitprojects\samplefolder (master -> origin)
λ git diff --name-only --relative --diff-filter AM master origin/master
readme.md

C:\gitprojects\samplefolder (master -> origin)
λ git diff --name-only --relative --diff-filter AM origin
Properties/sample.properties
readme.md
like image 772
Cante Ibanez Avatar asked Apr 27 '18 14:04

Cante Ibanez


1 Answers

Have a look at the man page for git diff (run man git-diff).

In the Description section, you can identify the 4th variant for invoking git diff as the one you are using. The man page details its usage like this:

git diff [--options] <commit> [--] [<path>...]
    This form is to view the changes you have in your working tree relative to the named <commit>. You can
    use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different
    branch.

In your case, you are using the String origin as the <commit> (or revision) you want to compare your working tree to. This cannot work, because origin is not a revision/commit. That's what the error message is telling you.

origin is a "remote". A remote is just a reference to another remote clone of the repository and git diff cannot make comparisons between whole repositories, only between revisions/commits.

You can resolve this by specifying a commit you want to compare to. One example would be origin/master, meaning to compare to the tip of the master branch on the remote called origin. What commit to specify exactly depends on what you are trying to find out specifically.

like image 136
anothernode Avatar answered Nov 08 '22 23:11

anothernode