重置后Git推送

问题描述 投票:2回答:1

我提交了一些不必要的代码,因此我使用了: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 git-push git-pull git-reset
1个回答
1
投票

如果您希望恢复上次提交,请使用git revert HEAD; git push执行此操作。这会创建一个在当前头部顶部推送的恢复提交。

如果您想删除最后一次提交,请使用git reset --hard HEAD^; git push --force执行此操作。 git保护您不会重写历史记录,因此需要强制推送才能删除远程中已存在的提交。

© www.soinside.com 2019 - 2024. All rights reserved.