什么应该"git rev-list origin..头"回来了?



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",这是一个远程而不是。我误解了什么?

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)解释了git remote set-head描述中的refs/remotes/<remote>/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.

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

正如您正确地说的,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):组选项;重新格式化;文档更多选项

我只能假设,origin的使用是一个错误,而不是字面上指的是远程。文档中充斥着不一致的例子(rev-list单独使用foo/bar/baz, origin/HEAD和A/B),所以我不会把太多的重量放在那上面。

重要的是,该命令应该与分支(或任何ref一般)一起工作,并且远程本身不是有效的ref。

最新更新