什么应该"git rev-list origin..HEAD"return?

What should "git rev-list origin..HEAD" return?

git-rev-list man page 显示以下命令:

$ 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' 这是一个远程的。我误解了什么?

正如您所说的那样,git rev-list 应该在那里占据一个提交范围,因此使用远程名称没有任何意义。

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

A special notation <commit1>..<commit2> can be used as a short-hand for ^<commit1> <commit2>.

然后 this commit (mailing list discussion) 更改为:

A special notation "'<commit1>'..'<commit2>'" can be used as a short-hand for "^'<commit1>' '<commit2>'". For example, either of the following may be used interchangeably:

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

该更改的提交消息如下:

git-rev-list(1): group options; reformat; document more options

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

虽然重要的部分是,该命令应该与分支一起工作(或一般的任何 ref),并且遥控器本身不是有效的引用。

git-rev-parse(1) 解释了如何将遥控器的名称用作 ref:

<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>/HEADgit 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.

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