“origin” 在 Git 中作为 git commitish 使用时指的是什么意思?

huangapple go评论56阅读模式
英文:

What does origin mean when it is used as a git commitish?

问题

我知道单词 origin 在 Git 中被用作远程仓库的默认别名,即如果推送没有明确指定推送到哪个仓库,分支将被推送到该别名所代表的远程仓库。但是当在期望分支名称的位置使用 origin 时,它的含义是什么?

例如,如果我输入以下 Git 命令:

git log origin..ntd-dev

Git 会返回所有 ntd-dev 分支有而 origin 没有的提交。但是没有名为 origin 的分支,所以 Git 是如何将远程别名 origin 转换成分支的呢?

英文:

I know that the word origin is used by git as the default alias for the remote repository, i.e. the repo to which branches are pushed if the push does not explicitly specify which repo to push to. But what does origin mean when used where one would expect the name of a branch?

For example, if I type the git command

<!--language: lang-git -->

git log origin..ntd-dev

git returns all the commits that ntd-dev has that origin does not have. But there is no branch called origin, so which branch is git translating the remote alias origin into?

答案1

得分: 4

根据git-log告诉,此行为在gitrevisions的“指定修订版本”部分有文档记录:

  1. 如果$GIT_DIR/<refname>存在,那就是你的意思(这通常仅对于HEAD、FETCH_HEAD、ORIG_HEAD、MERGE_HEAD和CHERRY_PICK_HEAD有用);
  2. 否则,如果存在refs/<refname>
  3. 否则,如果存在refs/tags/<refname>
  4. 否则,如果存在refs/heads/<refname>
  5. 否则,如果存在refs/remotes/<refname>
  6. 否则,如果存在refs/remotes/<refname>/HEAD

在这里,选项#6适用。

英文:

As git-log tells, this behaviour is documented in gitrevisions in the section Specifying revisions:

> 1. If $GIT_DIR/&lt;refname&gt; 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/&lt;refname&gt; if it exists;
> 3. otherwise, refs/tags/&lt;refname&gt; if it exists;
> 4. otherwise, refs/heads/&lt;refname&gt; if it exists;
> 5. otherwise, refs/remotes/&lt;refname&gt; if it exists;
> 6. otherwise, refs/remotes/&lt;refname&gt;/HEAD if it exists.

Here, option #6 applies.

huangapple
  • 本文由 发表于 2023年7月11日 02:36:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定