【发布时间】:2015-05-27 01:16:49
【问题描述】:
大师在说提交 #10。然而,我最终意识到我在测试过程中破坏了一些没有被测试发现的东西。
我最终要提交 #5,然后慢慢地重新进行每个提交的开发并不断调整它以确保它不会重新导致错误。现在我基本上回到了提交 #10,但有一些更改可以防止错误发生。
我现在想使用我的更改创建提交 #11。但是当我尝试推动掌握时,我得到了
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>
这是意料之中的。但是我如何才能真正将它推送到我的远程分支?
我试过git push origin HEAD:master,但后来得到了这个:
! [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.
当我执行git status 时,我看到HEAD detached from 4a74ac3
【问题讨论】:
-
您是否确保在 #10 之前的提交历史是原来的,并且只有您的提交 #11 包含更改?当您的分支和原始分支具有不同的提交历史时,通常会出现这样的错误(例如,当您重新进行每个提交的开发时会发生什么)
-
我很确定他们不会。我想我在签出 #5 后愚蠢地开始进行开发
-
没关系,您可以使用
git reset [commit10Hash]取消暂存更改,然后git stash将其保存一段时间,git reset --hard origin/nameofremotebranch将其重置为原点,git stash pop重新应用更改您想要的,然后git add .和git commit -m "Your new changes on top of origin"。然后你应该可以git push origin nameofremotebranch没有冲突