git remove commit on the server

对着背影说爱祢 提交于 2019-12-05 05:10:33

问题


i've made some mistakes about my project managed in git:

reading some guides and some posts here I made this command:

git reset --hard a77ec5f

where the commint a77ec5f is the last 'good' commit

after this, the files are right in my local copy, but if I do a git status:

$ git status
# On branch dev
# Your branch is behind 'origin/dev' by 4 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)

and now, how can I tell the server that the 4 commits that I'm behind are to remove? thanks


回答1:


If your repository is synced by others, then you should not push any history changes unless you are certain nobody has pulled the bad changes yet.

To rewrite history (dangerous), do an empty commit locally (git commit --allow-empty) to diverge your HEAD from the remote HEAD, then push --force to rewrite the server's history.




回答2:


you should not remove the commits on your server, but revert them




回答3:


You can revert the unwanted commits.

git revert commit

This will create another commit that reverts the unwanted changes. After you revert the unwanted commit, you should push to origin.

You can look for --no-commit parameter for reverting also.



来源:https://stackoverflow.com/questions/16809200/git-remove-commit-on-the-server

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