Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal: ambiguous argument '<branch_name>': both revision and filename

Here is what I did:

  • I ran git checkout -b branch_name.
  • I made some commits on branch_name.
  • I checked out the master branch and did a fast-foward merge.

When I run git log branch_name --oneline, I get the following message:

fatal: ambiguous argument 'branch_name': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

What could be the problem?

like image 404
Muli Avatar asked Oct 13 '14 21:10

Muli


3 Answers

It's telling you that you have a branch named 'branch_name' and also a file or a directory named 'branch_name'.

If you want the command to treat 'branch_name' as a branch use

git log --oneline branch_name --

if you want it to treat 'branch_name' as a file use

git log --oneline -- branch_name
like image 120
Andrew C Avatar answered Nov 07 '22 08:11

Andrew C


If in case any one faced when trying the following and got above error, here is the fix

Problem:-

#In master branch
git checkout -b feature-a

#changed to feature-a branch
vi a.txt
git commit -m "adding a file" a.txt
git push
git diff master

fatal: ambiguous argument 'master': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Solution:-

git diff origin/master
like image 45
narasimharaosp Avatar answered Nov 07 '22 08:11

narasimharaosp


Normally, I work with diff's with something like this:

git diff -r 2e706c4dd3 -r 838112ed50 > codereview.txt

...to make a nice codereview.txt file. Well, I accidentally ran this:

git diff -r 2e706c4dd3 -r 838112ed50 > 838112ed50

This makes the file 838112ed50 itself, which, then, makes the git diff command ambiguous, about whether I am trying to diff a file or a branch.

like image 1
HoldOffHunger Avatar answered Nov 07 '22 08:11

HoldOffHunger