git HEAD、master、origin的git概念是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8196544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:21:05  来源:igfitidea点击:

What are the git concepts of HEAD, master, origin?

git

提问by user779159

As I'm learning about git, I keep coming across the terms HEAD, master, origin, and I'm not sure what the differences are. If I understand correctly, HEAD is always equal to the latest revision? And if so, is that the latest revision of the whole repository, or of a specific branch or tag? This is so confusing. I've read so many tutorials on this and things like branching/merging, but still can't wrap my head around it.

在我学习 git 的过程中,我不断遇到 HEAD、master、origin 这些术语,我不确定它们之间的区别是什么。如果我理解正确,HEAD 总是等于最新修订版?如果是这样,那是整个存储库的最新版本,还是特定分支或标签的最新版本?这太令人困惑了。我已经阅读了很多关于此的教程以及分支/合并之类的内容,但仍然无法理解它。

回答by Matt Greer

I highly recommend the book "Pro Git" by Scott Chacon. Take time and really read it, while exploring an actual git repo as you do.

我强烈推荐Scott Chacon所著的“Pro Git”一书。花点时间认真阅读它,同时像您一样探索实际的 git 存储库。

HEAD: the current commit your repo is on. Most of the time HEADpoints to the latest commit in your current branch, but that doesn't have to be the case. HEADreally just means "what is my repo currently pointing at".

HEAD:您的回购所在的当前提交。大多数时间都HEAD指向当前分支中的最新提交,但情况并非如此。HEAD真的只是意味着“我的回购目前指向的是什么”。

In the event that the commit HEADrefers to is not the tip of any branch, this is called a "detached head".

如果提交HEAD所指的不是任何分支的尖端,这称为“分离头”。

master: the name of the default branch that git creates for you when first creating a repo. In most cases, "master" means "the main branch". Most shops have everyone pushing to master, and master is considered the definitive view of the repo. But it's also common for release branches to be made off of master for releasing. Your local repo has its own master branch, that almost always follows the master of a remote repo.

master: git 在第一次创建 repo 时为你创建的默认分支的名称。在大多数情况下,“master”的意思是“主分支”。大多数商店让每个人都推动掌握,掌握被认为是回购的权威观点。但是,发布分支由 master 组成以进行发布也很常见。你的本地仓库有自己的主分支,它几乎总是跟随远程仓库的主分支。

origin: the default name that git gives to your main remote repo. Your box has its own repo, and you most likely push out to some remote repo that you and all your coworkers push to. That remote repo is almost always called origin, but it doesn't have to be.

origin: git 给你的主远程仓库的默认名称。你的盒子有自己的仓库,你很可能推送到一些你和你所有同事推送到的远程仓库。那个远程仓库几乎总是被称为 origin,但它不一定是。

HEADis an official notion in git. HEADalways has a well-defined meaning. masterand originare common names usually used in git, but they don't have to be.

HEAD是 git 中的官方概念。HEAD总是有明确的含义。masterorigin是 git 中通常使用的常用名称,但它们不一定是。

回答by svick

HEADis not the latest revision, it's the currentrevision. Usually, it's the latest revision of the current branch, but it doesn't have to be.

HEAD不是最新版本,而是当前版本。通常,它是当前分支的最新版本,但并非必须如此。

masteris a name commonly given to the main branch, but it could be called anything else (or there could be no main branch).

master是一个通常给主分支的名称,但它可以被称为其他任何东西(或者可能没有主分支)。

originis a name commonly given to the main remote. remote is another repository that you can pull from and push to. Usually it's on some server, like github.

origin是主遥控器的常用名称。remote 是另一个可以从中拉取和推送到的存储库。通常它在某个服务器上,比如 github。

回答by Piotr Perak

While this doesn't directly answer the question, there is great book available for free which will help you learn the basics called ProGit. If you would prefer the dead-wood version to a collection of bits you can purchase it from Amazon.

虽然这并不能直接回答问题,但有一本很棒的免费书籍可以帮助您学习称为ProGit的基础知识 。如果您更喜欢枯木版本而不是一系列钻头,您可以从亚马逊购买。