git HEAD 和 master 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4386959/
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 09:37:15  来源:igfitidea点击:

Difference between HEAD and master

gitgithubheadmaster

提问by Frederik Heyninck

What is the difference between the HEADand masterin Git?

Git 中的HEAD和 有什么区别master

I did a clone of a project on GitHub and want to push my changes to the remote. But to which one should I push?

我在 GitHub 上克隆了一个项目,想将我的更改推送到远程。但是我应该推到哪一个?

screenshot

截屏

回答by Lee Netherton

masteris a reference to the end of a branch. By convention (and by default) this is usually the main integration branch, but it doesn't have to be.

master是对分支结尾的引用。按照惯例(默认情况下),这通常是主要的集成分支,但并非必须如此。

HEADis actually a special type of reference that points to another reference. It may point to masteror it may not(it will point to whichever branch is currently checked out). If you know you want to be committing to the masterbranch then push to this.

HEAD实际上是一种特殊类型的引用,它指向另一个引用。它可能指向master也可能不指向(它将指向当前检出的任何分支)。如果你知道你想提交到master分支,那么推送到这个。

Here is a visual example:

这是一个视觉示例:

alt text

替代文字

On your own repository you can check where the HEADis pointing to by running this:

在您自己的存储库中,您可以HEAD通过运行以下命令来检查指向的位置:

$ git symbolic-ref HEAD
refs/heads/master

However, finding out where the remotes/origin/HEADis pointing to is more tricky because it is on the remote machine.

但是,找出remotes/origin/HEAD指向的位置更加棘手,因为它在远程机器上。

There is a great little tutorial on git references here:

这里有一个关于 git 参考的很棒的小教程:

http://people.gnome.org/~federico/news-2008-11.html#pushing-and-pulling-with-git-1

http://people.gnome.org/~federico/news-2008-11.html#pushing-and-pulling-with-git-1

回答by benhorgen

The simple answer is that HEADis a pointer/label to the most recent commit of the branch you are currently on. masteris the default branch created when you initialized a git repository (e.g. git init).

简单的答案是,它HEAD是指向您当前所在分支的最新提交的指针/标签。master是初始化 git 存储库(例如git init)时创建的默认分支。

You can delete the masterbranch (e.g. git branch -D master). You cannot delete the HEADpointer.

您可以删除master分支(例如git branch -D master)。您不能删除HEAD指针。

回答by VonC

Simply push the changes of your current branch

只需推送当前分支的更改

git push origin

and it will push your branch 'B' changes to 'origin/B'.
If you are on your masterbranch, git will push to origin/master.
Actually it will push all changes on the local branches that have matching remote branches at origin. It is controlled by the config setting push.default.
See also pushing RefSpecs in the Pro Git book.

它会将您的分支“ B”更改为“ origin/B”。
如果你在你的master分支上,git 会推送到origin/master.
实际上,它会将所有更改推送到具有匹配远程分支的本地分支上origin。它由配置设置push.default 控制
另请参阅Pro Git 书中的 push RefSpecs



What you are seeing is the sidebar representing all the refspecs of your remote repo in the Experimental GitX forkof the GitX project.

您所看到的是侧边栏,它代表了GitX 项目实验性 GitX 分支中远程存储库的所有引用规范

alt text

替代文字

The HEADwill designate the default branch for that remote.
See git remote set-headman page:

HEAD将指定默认分支为远程。
请参阅git remote set-head手册页

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 originis set to master, then originmay be specified wherever you would normally specify origin/master.

不需要远程的默认分支,但允许指定远程的名称代替特定分支。
例如,如果默认分支origin设置为master,则origin可以在您通常指定的任何位置指定origin/master