Git push after reset

杀马特。学长 韩版系。学妹 提交于 2019-12-11 01:44:07

问题


I committed some unnecessary code so I used: git reset HEAD~

I checked out the files and tried to push my last commits (which were correct). However, I'm receiving error: error: failed to push some refs to 'git@github.com:MyProject/MyProject.git' hint: Updates were rejected because the tip of your current branch is behind which is probably since the commit is not reverted correctly since when I do git pull, the commit is back again. How can I correctly revert this commit?

additional info: git status gives me:

Your branch is behind 'origin/Mybranch' by 1 commit, and can be fast-forwarded.

回答1:


If you wish to revert the last commit, do so with git revert HEAD; git push. This creates a revert commit which is pushed on top of the current head.

If you wish to remove the last commit, do so with git reset --hard HEAD^; git push --force. git protects you against rewriting history, so a forced push is needed to remove commits that already exist in the remote.



来源:https://stackoverflow.com/questions/49114300/git-push-after-reset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!