简体   繁体   English

git 将分离的头部推送到远程的开发分支

[英]git push a detached head to a dev branch of remote

When git push to remote repo of dev branch, it reportgit push送到 dev 分支的远程仓库时,它报告

[detached HEAD 0091d9a] 2019-10-27 14:13:10
 1 file changed, 1 deletion(-)
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Review the branches审查分支机构

-  (press RETURN)
* (HEAD detached from be1d973)
  develop
  master

Should I run我应该跑吗

git push origin HEAD:develop

push it the current modifications to develop branch?将当前的修改推送到开发分支? I'm afraid of potential damage.我害怕潜在的损害。

The question:问题:

Should I _____?我是不是该 _____?

is fraught with danger regardless of what goes in the blank.无论空白处发生什么,都充满了危险。 1 1

The question as to whether you can do that is much simpler: yes, you can do that ( git push origin HEAD:develop ).关于您是否可以这样做的问题要简单得多:是的,您可以这样做( git push origin HEAD:develop )。 What that will do is call up the other Git, send them any new commit(s) needed—such as 0091d9a —and then ask them to set their branch develop to point to this particular commit.这将调用另一个 Git,向他们发送所需的任何新提交(例如0091d9a ),然后要求他们将分支develop设置为指向此特定提交。 If they think it's OK for them to set their develop , they will do so.如果他们认为他们可以设置他们的develop ,他们就会这样做。 If they think it is not OK, they will refuse this request.如果他们认为不合适,他们会拒绝这个请求。 With luck, if they do refuse the request, they will also tell you why they think it is not OK.幸运的是,如果他们拒绝了请求,他们也会告诉你为什么他们认为这不合适。

If they accept, they've put the new commit(s) on their develop , and all the old commits that were already on their develop remain on their develop .如果他们接受,他们就会将新的提交放在他们的develop上,并且所有已经在develop上的旧提交仍然在他们的develop上。 That's probably pretty safe, but we don't know enough about how other people are using this other Git repository, nor about your commit(s), to answer that kind of question.这可能很安全,但我们对其他人如何使用这个其他 Git 存储库以及您的提交都不够了解,无法回答这类问题。


1 Should I drive a car fast (where "fast" means, say, 50 to 70 mph or about 100 km/h)? 1我应该开快车吗? Is that dangerous?那很危险吗? What if I'm in a car on a freeway, where all the other cars are also driving fast?如果我在高速公路上的汽车里,而所有其他汽车也在快速行驶,该怎么办? In that case, might it be dangerous to drive very slowly?在那种情况下,开得很慢会不会很危险? What if I drive at 15 mph / 25 km/h in the fast lane of the freeway?如果我在高速公路的快车道上以 15 英里/小时/25 公里/小时的速度行驶会怎样? What if I'm in a car in a parking lot or residential street?如果我在停车场或住宅街的车里怎么办?

@torek has got you covered, but I think it's worth listing a couple of other options: @torek 已经为您服务,但我认为值得列出其他几个选项:

  • create a branch from your HEAD: git checkout -b name/of/branch and then merge this into remote develop从您的 HEAD 创建一个分支: git checkout -b name/of/branch然后将其合并到远程开发中
  • create a branch from your head, merge this branch into your local develop and push your develop - this seems cleaner than pushing a branch directly onto develop, this workflow will also show you any merge conflicts earlier.从您的头部创建一个分支,将此分支合并到您的本地develop并推送您的develop - 这似乎比直接将分支推送到开发更干净,此工作流程还将更早地向您显示任何合并冲突。
  • If Pull Requests are supported, then create a branch from your HEAD push this branch to the remote and create a Pull Request from this branch to develop .如果支持拉取请求,则从您的 HEAD 创建一个分支,将此分支推送到远程,并从该分支创建一个拉取请求以develop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM