我提交了一些不必要的代码,所以我使用了:
git reset HEAD~
我检查了文件并尝试推送我的最后提交(这是正确的)。但是,我收到错误:error: failed to push some refs to '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d4a44596d4a445945584f034e4240" rel="noreferrer noopener nofollow">[email protected]</a>: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 推送
。这将创建一个恢复提交,该提交被推送到当前头的顶部。
如果您希望删除最后一次提交,请使用git reset --hard HEAD^; git push --force
。 git 可以防止您重写历史记录,因此需要强制推送来删除远程中已存在的提交。
关于重置后Git推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49114300/