Git 分支命名为 origin/HEAD -> origin/master

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

Git branch named origin/HEAD -> origin/master

git

提问by Tauren

I'm fairly new to Git, and still getting the hang of it. I just recently started working with branches and am running into some questions.

我对 Git 相当陌生,并且仍然掌握它的窍门。我最近才开始与分支机构合作,并且遇到了一些问题。

I have two development systems, an Ubuntu desktop and an MacBookPro. I did a bunch of work in a new organizationsbranch on the Ubuntu system and performed commits and pushed to my remote repo. At this point, I had these branches:

我有两个开发系统,一个 Ubuntu 桌面和一个 MacBookPro。我organizations在 Ubuntu 系统的一个新分支中做了很多工作,并执行了提交并推送到我的远程仓库。在这一点上,我有这些分支:

tauren@ubuntu:/projects$ git branch
  accounting
  master
* organizations

tauren@ubuntu:/projects$ git branch -r
  origin/accounting
  origin/master
  origin/organizations
  origin/superstar

Then I switched to the MBP to pull the new branch:

然后我切换到 MBP 来拉新分支:

tauren@osx:/projects$ git branch
  accounting
* master

tauren@osx:/projects$ git branch -r
  origin/HEAD -> origin/master
  origin/accounting
  origin/master
  origin/superstar

tauren@osx:/projects$ git pull
   2e20a14..ef35730  accounting -> origin/accounting
   271a1a5..7e947ab  master     -> origin/master
 * [new branch]      organizations -> origin/organizations

tauren@osx:/projects$ git branch
* accounting
  master

tauren@osx:/projects$ git branch -r
  origin/HEAD -> origin/master
  origin/accounting
  origin/master
  origin/organizations
  origin/superstar

So my questions are these:

所以我的问题是:

  1. Why does the MBP have a branch origin/HEAD -> origin/master, but the Ubuntu system doesn't? What is that branch?
  2. Does git pullautomatically pull all new remote branches? I thought I had to tell it the name of new branches to pull. As you can see, it pulled the remote organizationsbranch on the commmand git pull.
  1. 为什么 MBP 有分支origin/HEAD -> origin/master,而 Ubuntu 系统没有?那个分支是什么?
  2. 是否git pull自动拉取所有新的远程分支?我想我必须告诉它要拉的新分支的名称。如您所见,它在命令上拉取了远程organizations分支git pull

采纳答案by Jan Krüger

HEADusually points to the currently checked out branch. In hosted (bare) repositories, it designates the default branch, i.e. the branch that is checked out when you clone the repository. So, origin/HEAD tells you the default branch of origin.

HEAD通常指向当前签出的分支。在托管(裸)存储库中,它指定默认分支,即克隆存储库时检出的分支。因此,origin/HEAD 会告诉您原始的默认分支。

I don't know why it's not present in your repository on the Ubuntu system. Perhaps you originally pushed your code from that repository (when origin was empty and thus didn't have a HEAD yet) and never updated it.

我不知道为什么它没有出现在您的 Ubuntu 系统上的存储库中。也许您最初从该存储库推送您的代码(当 origin 为空并且因此还没有 HEAD 时)并且从未更新它。

Having something like origin/HEAD is not terribly important in practice, anyway. If you want, you can use git remote set-head origin -ato have origin/HEADcreated/updated

无论如何,拥有像 origin/HEAD 这样的东西在实践中并不是非常重要。如果你愿意,你可以使用git remote set-head origin -aorigin/HEAD创建/更新

To answer your other question: if you run git pullwithout arguments, it actually fetches everything from the remote (git fetchis run without arguments, too, so it just gets everything). Everything doesn't get merged, though. Only the remote-tracking branches (the stuff in git branch -r) are updated.

回答您的另一个问题:如果您git pull不带参数运行,它实际上会从远程获取所有内容(git fetch也是不带参数运行的,因此它只会获取所有内容)。但是,一切都不会合并。仅git branch -r更新远程跟踪分支( 中的内容)。

回答by ulidtko

As far as I know, HEADis not a branch, but rather a pointer to a node of the history tree (i.e. a commit). The files which are residing in you particular working copy have the state described by HEAD.

据我所知,HEAD不是分支,而是指向历史树节点的指针(即提交)。驻留在您的特定工作副本中的文件具有由 描述的状态HEAD

Usually HEADpoints to the most recent commit in a branch, so you have the most recent files in the working copy. Using git reset HEAD^you can shift the pointer to previous commit (i.e. undoing the last commit in your local copy).

通常HEAD指向分支中最近的提交,因此您在工作副本中拥有最新的文件。使用git reset HEAD^您可以将指针移至上一次提交(即撤消本地副本中的最后一次提交)。

Now, every git repo has a HEAD, check this with git show HEAD. Accordingly, origin/HEADis HEADof your originremote.

现在,每个 git repo 都有一个HEAD,用git show HEAD. 因此,origin/HEADHEAD您的origin遥控器。

Now, I've found a good question describing HEAD: What is HEAD in Git?

现在,我发现了一个很好的问题描述HEADGit 中的 HEAD 是什么?

回答by Gabriel

It is just a pointer to master, a symbolic link if you wish. You can safely delete it by doing the following in a terminal (or git bash/cygwin for windows users):

如果您愿意,它只是一个指向 master 的指针,一个符号链接。您可以通过在终端(或 Windows 用户的 git bash/cygwin)中执行以下操作来安全地删除它:

  1. navigate to your repository
  2. execute: git remote set-head origin -d
  1. 导航到您的存储库
  2. 执行: git remote set-head origin -d

now it should be gone:

现在它应该消失了:

$ git branch -r
origin/master