git 从 github 中删除提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10817906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete a commit from github
提问by Jistanidiot
Possible Duplicate:
How can I remove a commit on github?
How to delete a 'git commit'
So I'm trying to remove a commit from github.
所以我试图从 github 中删除一个提交。
It is 3 commits ago and I'm ok if all the changes are lost.
这是 3 次提交前,如果所有更改都丢失了,我就可以了。
So based on questions from here, I did a
所以根据这里的问题,我做了一个
git reset --hard <sha-commit-name-to-go-back-to>
git push -f origin HEAD^:master
Now it is gone from github as well as in git log.
现在它从 github 和 git log 中消失了。
I then redid my changes and did
然后我重新修改了我的更改并做了
git add <file I changed>
git commit
git log
Everything looks fine. There's no trace of the old commits. So I finally did a:
一切看起来都很好。没有旧提交的痕迹。所以我终于做了一个:
git push
Now suddenly github has those three commits that I had removed.
现在 github 突然有了我删除的那三个提交。
What am I doing wrong? How to I keep the commits from returning?
我究竟做错了什么?如何防止提交返回?
采纳答案by Aneesh Narayanan
Use git rebase process before applying new changes. After rebasing add the new changes and commit.
在应用新更改之前使用 git rebase 过程。在变基后添加新的更改并提交。
git rebase -i HEAD~2
git push origin +master