git 致命:不明确的参数“<branch_name>”:修订版和文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26349191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:34:57  来源:igfitidea点击:

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

gitversion-control

提问by Sayari

Here is what I did:

这是我所做的:

  • I ran git checkout -b branch_name.
  • I made some commits on branch_name.
  • I checked out the masterbranch and did a fast-foward merge.
  • 我跑了git checkout -b branch_name
  • 我在branch_name.
  • 我检查了master分支并进行了快速合并。

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

当我运行时git log branch_name --oneline,我收到以下消息:

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?

可能是什么问题呢?

回答by Andrew C

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

它告诉您您有一个名为“branch_name”的分支以及一个名为“branch_name”的文件或目录。

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

如果您希望命令将“branch_name”视为分支,请使用

git log --oneline branch_name --

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

如果您希望它将“branch_name”视为文件,请使用

git log --oneline -- branch_name

回答by narasimharaosp

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

回答by HoldOffHunger

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

通常,我使用 diff 的方法是这样的:

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

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

...制作一个不错的 codereview.txt 文件。好吧,我不小心运行了这个:

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

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

这使得文件838112ed50本身,然后,这使得git diff命令对于我是尝试对文件还是分支进行差异化变得模棱两可。