要恢复到 1be25fe,您需要运行以下命令,这会将 HEAD 移回 1be25fe。然后,您可以通过执行推送将其推送到上游。
git reset --hard 1be25fe # revert back to 1be25fe
git status #to check to see that it has reverted correctly, and see if there are any other issues.
git push origin stable #push the changes and recreated the branch upstream
// 编辑
为了解决您的“提示”错误,您可以将-f
参数添加到推送中。此参数强制远程存储库中的更改。我之前遇到过同样的问题,而且效果很好。
git push -f origin stable
// 编辑 2
如果您想实际删除提交,您需要查看变基:http: //git-scm.com/book/en/Git-Branching-Rebasing
// 编辑 3
要将更改与 4b2b148 合并,您需要执行以下操作:
git checkout -b important_changes origin/stable # branch off from the current state
git cherry-pick 4b2b148 # retrieve the commit containing the changes and insert it ahead of 1be25fe
git checkout stable # switch back to the older branch
git merge important_changes # merge in the important changes
git commit -am 'merged important changes' # commit the changes
git push origin stable # push the branch to master
git branch -d important_changes # remove the temp branch.
警告:当您合并important_changes
和时,您可能会遇到一些合并问题stable
。在推动之前确保它们已固定。