问题描述
师父说的是#10。然而,最终我意识到我在测试中没有抓住一些东西。我最终要提交#5,然后慢慢地重新做了每次提交的开发并不断调整以确保它不会导致错误。现在我基本上已经回到了第10步,但是有一些更改可以防止发生错误。
现在我想使用我的更改创建提交#11 。但是,当我尝试推送给主人时,我得到了
致命:您当前不在分支上。
现在使用
来推送当前(分离的HEAD)
状态的历史记录,git push master HEAD:<远程分支名称>
这是预期的。但我该如何真正把它推到我的远程分支?
我试过 git push origin HEAD:master
然后得到这个:
! [被拒绝] HEAD - >主(非快进)
错误:未能将某些参考推送到'https://github.com/tomhammond/sample.git'
提示:更新被拒绝是因为推送的分支提示是在其远程
背后:对应。检查此分支并在再次推送之前集成远程更改
提示:(例如'git pull ...')。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。
当我做一个 git status
我看 HEAD detached from 4a74ac3
致命:您当前不在分支上。
推动导致当前(分离的HEAD)的历史
在分离状态下工作不是预期的,除非您故意要这样做,我怀疑你的情况。您应该将 master
分支还原为该提交,或者执行 git rebase
而不是检出第5个提交>在交互模式下,您可以根据需要重新提交提交。
就是说,如果您确定 master
处于分离状态是你真正想要保留的,那么你可以绕过
非快进
错误,通过强制将分支推送到远程:
git push origin HEAD:master --force
但是,如果您强制推送,则可能会导致所有其他检出该分支的用户出现问题。风险较小的解决方案是从分离的HEAD创建临时分支,然后将该分支合并到 master
中:
git branch temp-branch
git checkout master
git merge temp-branch
git push origin master
Master is it at say commit #10. However, I ended up realizing I broke something along the way that wasn't caught by tests.
I ended up going to commit #5, and then slowly re-did the dev of each commit and adjusted it continually to ensure it didn't re-cause the bug. Now I'm essentially back to commit #10, but with a number of changes that prevent the bug from happening.
I now want to create commit #11 using my changes. But when I try to push to master I get
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push master HEAD:<name-of-remote-branch>
Which is to be expected. But how do I actually get that to push up to my remote branch?
I tried git push origin HEAD:master
but then got this:
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/tomhammond/sample.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
When I do a git status
I see HEAD detached from 4a74ac3
fatal: You are not currently on a branch.To push the history leading to the current (detached HEAD)
Working in a detached state is not to be expected, unless you deliberately want to be doing this, which I doubt is the case for you. Instead of checking out commit #5, you should have either reverted the master
branch to that commit, or do a git rebase
in interactive mode where you can rehash the commits as you want.
That being said, if you are certain that the version of master
in the detached state is what you really want to keep, then you can get around the non-fast-forward
error, by force pushing the branch to the remote:
git push origin HEAD:master --force
However, if you force push you run the risk of causing problems for all other users who have that branch checked out. A less risky solution would be to create a temporary branch from the detached HEAD, and then merge that branch into master
:
git branch temp-branch
git checkout master
git merge temp-branch
git push origin master
这篇关于Git推动主人致命:你目前不在分支上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!