英文:
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的“指定修订版本”部分有文档记录:
- 如果
$GIT_DIR/<refname>
存在,那就是你的意思(这通常仅对于HEAD、FETCH_HEAD、ORIG_HEAD、MERGE_HEAD和CHERRY_PICK_HEAD有用); - 否则,如果存在
refs/<refname>
; - 否则,如果存在
refs/tags/<refname>
; - 否则,如果存在
refs/heads/<refname>
; - 否则,如果存在
refs/remotes/<refname>
; - 否则,如果存在
refs/remotes/<refname>/HEAD
。
在这里,选项#6适用。
英文:
As git-log tells, this behaviour is documented in gitrevisions in the section Specifying revisions:
> 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.
Here, option #6 applies.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论