2

git-rev-list 手册页显示以下命令:

$ git rev-list origin..HEAD
$ git rev-list HEAD ^origin

但是,当我运行第一个命令时,出现以下错误:

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

'origin' 指的是以下遥控器:

$ git remote -v
origin  c:/hands_on/git/learn/clone/../repo_1 (fetch)
origin  c:/hands_on/git/learn/clone/../repo_1 (push)

我是否错误地使用了该命令?另外,我认为 rev-list 命令将提交作为输入,所以我不清楚为什么手册页使用远程的 'origin'。我误解了什么?

4

2 回答 2

3

git-rev-parse(1) 解释了如何将远程的名称用作参考:

<refname>, e.g. master, heads/master, refs/heads/master
   A symbolic ref name. E.g.  master typically means the commit object
   referenced by refs/heads/master. If you happen to have both heads/master and
   tags/master, you can explicitly say heads/master to tell Git which one you
   mean. When ambiguous, a <refname> is disambiguated by taking the first match
   in the following rules:

    1. If $GIT_DIR/<refname> exists, that is what you mean (this is usually
    useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and
    CHERRY_PICK_HEAD);

    2. otherwise, refs/<refname> if it exists;

    3. otherwise, refs/tags/<refname> if it exists;

    4. otherwise, refs/heads/<refname> if it exists;

    5. otherwise, refs/remotes/<refname> if it exists;

    6. otherwise, refs/remotes/<refname>/HEAD if it exists.

并且 git-remote(1) 解释refs/remotes/<remote>/HEAD了描述中的内容git remote set-head

   set-head
       Sets or deletes the default branch (i.e. the target of the symbolic-ref
       refs/remotes/<name>/HEAD) for the named remote. Having a default branch
       for a remote is not required, but allows the name of the remote to be
       specified in lieu of a specific branch. For example, if the default
       branch for origin is set to master, then origin may be specified wherever
       you would normally specify origin/master.

换句话说,它使用远程的默认分支,而您似乎没有。

于 2015-09-20T22:11:42.793 回答
2

正如你所说的那样,git rev-list应该在那里接受一个提交范围,所以使用远程的名称并没有真正的意义。

之前的文档(2006 年之前,很久以前)说如下:

<commit1>..<commit2>可以使用特殊符号作为 的简写^<commit1> <commit2>

然后通过此提交邮件列表讨论)将其更改为:

"'<commit1>'..'<commit2>'"可以使用特殊符号作为 的简写"^'<commit1>' '<commit2>'"。例如,以下任何一个都可以互换使用:

$ git-rev-list origin..HEAD
$ git-rev-list HEAD ^origin

该更改的提交消息如下:

git-rev-list(1):组选项;重新格式化;记录更多选项

我只能假设,使用originthere 是一个错误,并不意味着字面意思是指遥控器。文档中充斥着不一致的示例(rev-list单独使用 foo/bar/baz、origin/HEAD 和 A/B),所以我不会对此过于重视。

但重要的部分是,该命令应该与分支(或任何一般的参考)一起使用,并且遥控器本身不是有效的参考。

于 2015-09-20T17:18:56.680 回答