Git 拉原点 HEAD
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12532913/
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
Git pull origin HEAD
提问by Rican7
I was taught that you could push to and pull from a remote branch matching the name of your current Git branch by doing:
我被教导你可以通过执行以下操作来推送和拉出与当前 Git 分支名称匹配的远程分支:
git push origin HEAD
or
或者
git pull origin HEAD
Its always worked for me before, but it strangely doesn't work sometimes, instead deferring to push/pulling from the masterbranch instead (which causes a merge on pull... not what I want to do). I know that you can easily push/pull from the branch you're on by simply using the name of the branch like:
它以前一直对我有用,但奇怪的是有时它不起作用,而是推迟从主分支推/拉(这会导致合并拉...不是我想做的)。我知道您可以通过简单地使用分支的名称轻松地从您所在的分支推/拉:
git pull origin name-of-branch-i-want-to-pull-from
Anyway:
无论如何:
- Is there some reason that the HEAD is losing track/not pointing to my current branch, like it almost always does?
- Is there any way to push/pull to the branch that I'm currently working on (as long as the remote branch's name matches) without explicitly naming the branch in the command?
- 是否有某种原因导致 HEAD 丢失轨道/不指向我当前的分支,就像它几乎总是这样?
- 有没有办法推/拉到我当前正在处理的分支(只要远程分支的名称匹配)而无需在命令中明确命名分支?
采纳答案by Rican7
Thanks to some serious help by @abackstrom, I was able to fix my issue. Essentially, this post was my problem, and solution:
感谢@abackstrom 的一些认真帮助,我能够解决我的问题。本质上,这篇文章是我的问题和解决方案:
Git branch named origin/HEAD -> origin/master
Git 分支命名为 origin/HEAD -> origin/master
The exact command to "recreate"/track a local HEAD branch/pointer correctly was:
正确“重新创建”/跟踪本地 HEAD 分支/指针的确切命令是:
git remote set-head origin -a
I hope this helps anyone else that runs into this issue.
我希望这可以帮助遇到此问题的任何其他人。
回答by twalberg
HEAD is not really a branch. It's a pointer to the commit that you currently have checked out, and will often reference a branch, but if you do something like git checkout <sha>
or git checkout <tag>
, then HEAD references a commit directly, with no tie to a branch - this is called a "detached HEAD" state, and you should normally get a warning from git checkout
when you enter such a state. In that state, trying to push/pull HEAD doesn't make sense, since you're not on a branch.
HEAD 并不是一个真正的分支。它是指向您当前已签出的提交的指针,并且通常会引用一个分支,但是如果您执行类似git checkout <sha>
或 的操作git checkout <tag>
,则 HEAD 将直接引用一个提交,而与分支没有联系 - 这称为“分离的 HEAD”状态,git checkout
当您进入这种状态时,您通常应该收到警告。在那种状态下,尝试推/拉 HEAD 没有意义,因为您不在分支上。