致命:参数"origin"模棱两可:未知修订或路径不在工作树中 [英] fatal: ambiguous argument 'origin': unknown revision or path not in the working tree

查看:558
本文介绍了致命:参数"origin"模棱两可:未知修订或路径不在工作树中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去经常使用git diff origin.

在其他环境中,它不起作用.我不知道为什么.

In a different environment it does not work. I have no clue why.

user@host> git diff origin
fatal: ambiguous argument 'origin': unknown revision or path 
       not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

状态:

user@host> git status
On branch master
nothing to commit, working directory clean

远程:

user@host> git remote -v
origin  https://example.com/repos/djangotools (fetch)
origin  https://example.com/repos/djangotools (push)

版本:

user@host> git --version
git version 2.7.4

使用"git版本1.8.1.4"时,git diff origin起作用.

With "git version 1.8.1.4" git diff origin works.

顺便说一句如果我使用"git diff origin/master",我会看到相同的err msg

BTW2,我认为"/master"是多余的.理智的默认设置是将本地分支与远程站点上的同一分支进行比较.

BTW2, I think the "/master" is redundant. The sane default is to compare the local branch with the same branch on the remote site.

推荐答案

git diff命令通常期望一个或多个提交哈希值来生成差异.您似乎正在提供遥控器的名称.

The git diff command typically expects one or more commit hashes to generate your diff. You seem to be supplying the name of a remote.

如果您有一个名为origin的分支,那么如果您向diff命令提供origin,则将使用该分支顶端的提交哈希,但是当前(没有对应的分支)该命令将产生错误你看到了.可能是以前使用过名为origin的分支的情况.

If you had a branch named origin, the commit hash at tip of the branch would have been used if you supplied origin to the diff command, but currently (with no corresponding branch) the command will produce the error you're seeing. It may be the case that you were previously working with a branch named origin.

另一种选择是,如果您试图查看本地分支与远程分支之间的区别,则类似于:

An alternative, if you're trying to view the difference between your local branch, and a branch on a remote would be something along the lines of:

git diff origin/<branchname>

git diff <branchname> origin/<branchname>

或其他已记录的变体.

进一步阅读后,我意识到我略有错误,git diff origin是与指定遥控器的头部进行对比的简写,因此git diff origin = git diff origin/HEAD(将本地git分支与远程分支进行比较?)

Having read further, I realise I'm slightly wrong, git diff origin is shorthand for diffing against the head of the specified remote, so git diff origin = git diff origin/HEAD (compare local git branch with remote branch?, Why is "origin/HEAD" shown when running "git branch -r"?)

听起来您的来源没有HEAD,就我而言,这是因为我的遥控器是一个从未设置HEAD的裸仓库.

It sounds like your origin does not have a HEAD, in my case this is because my remote is a bare repository that has never had a HEAD set.

正在运行git branch -r将会显示是否设置了origin/HEAD,如果设置了,它会指向哪个分支(例如origin/HEAD -> origin/<branchname>).

Running git branch -r will show you if origin/HEAD is set, and if so, which branch it points at (e.g. origin/HEAD -> origin/<branchname>).

这篇关于致命:参数"origin"模棱两可:未知修订或路径不在工作树中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆