我提交了一些不必要的代码,因此我使用了:git reset HEAD~
我检查了文件并尝试推送我的最后提交(这是正确的)。但是,我收到错误:error: failed to push some refs to '[email protected]:MyProject/MyProject.git'
hint: Updates were rejected because the tip of your current branch is behind
,这可能是因为提交没有正确恢复,因为当我执行git pull时,提交又回来了。如何正确还原此提交?
其他信息:git status
给了我:
Your branch is behind 'origin/Mybranch' by 1 commit, and can be fast-forwarded.
如果您希望恢复上次提交,请使用git revert HEAD; git push
执行此操作。这会创建一个在当前头部顶部推送的恢复提交。
如果您想删除最后一次提交,请使用git reset --hard HEAD^; git push --force
执行此操作。 git保护您不会重写历史记录,因此需要强制推送才能删除远程中已存在的提交。