git diff 给出了模棱两可的论点错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33152725/
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
git diff gives ambigious argument error
提问by am28
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:
我最近从 SVN 转移到了 git,并试图学习我的 git 方法。我需要找到在我的存储库的 2 个分支之间发生更改的文件。我使用以下命令:
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 给出以下 o/p:
git branch -a
* branch_1
master/origin
remotes/origin/HEAD -> origin/master
remotes/origin/branch_2
remotes/origin/branch_1
回答by idjaw
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.
这将不起作用,如您的 git 分支列表中所列,您的“遥控器”被指定为“原点”。这实际上意味着您的遥控器上有这些分支,但它们实际上并未在本地签出。
So you have two options here. Try these, and let me know how it goes.
所以你在这里有两个选择。试试这些,让我知道它是怎么回事。
Based on the branch list provided:
根据提供的分支列表:
Diff using origin/
Diff 使用 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
回答by Gen.Stack
Sometimes you got a shallow git repo, created using
有时你会得到一个浅的 git repo,使用创建
git clone --depth 1 <repo-url>
Trying to git diff
fails w/ a fatal: ambiguous argument error
:
尝试git diff
失败 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 fetchand git unshallow.
然后,您需要使您的 refs 在本地可用。将浅的 git 存储库从浅的存储库转换为完整的(非浅层的)存储库,请参阅git deep fetch和git unshallow。
Then it should be able to git diff
branches:
然后它应该能够git diff
分支:
git diff branch1
Aformentioned example compares branch1
to the active working branch.
上述示例与branch1
活动工作分支进行比较。
HTH
HTH