【问题标题】:What should "git rev-list origin..HEAD" return?“git rev-list origin..HEAD”应该返回什么?
【发布时间】:2015-09-20 17:01:21
【问题描述】:

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 git-rev-list


    【解决方案1】:

    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/&lt;remote&gt;/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.
    

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

    【讨论】:

    • 在为远程建立默认分支后,它可以工作: $ git remote set-head origin master $ git rev-list origin..HEAD f8def1b0a13f8a2d83b6f538416358979e86a890
    • @Ltf4an 在尝试设置默认分支后出现错误:Not a valid ref: refs/remotes/origin/master。我该如何解决?
    【解决方案2】:

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

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

    一个特殊的符号&lt;commit1&gt;..&lt;commit2&gt; 可以用作 ^&lt;commit1&gt; &lt;commit2&gt; 的简写。

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

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

    $ 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)一起使用,并且远程本身不是有效的参考。

    【讨论】:

    • @minitech 一个远程branch,当然,但不是远程。即使采用默认的上游分支(您无法在远程级别定义,但只能在本地分支的上下文中定义 - rev-list 不可用),它也没有多大意义。您确定您的存储库中的某处没有名为origin 的引用(分支/标签/某物)吗? git rev-parse origin 显示什么?
    • 不,遥控器。请参阅 git-rev-parse(1):“6.否则,如果存在,则为 refs/remotes//HEAD。”
    • 这真的很奇怪。我根本无法重现……
    猜你喜欢
    • 2018-04-16
    • 2019-07-31
    • 2020-11-23
    • 2014-06-08
    • 1970-01-01
    • 2014-04-11
    • 2012-01-02
    • 1970-01-01
    • 2012-09-14
    相关资源
    最近更新 更多