简体   繁体   English

撤消推送到源的最后一个git commit

[英]undo last git commit that is pushed to origin

I have committed wrong files to my branch and pushed it to origin. 我已将错误的文件提交给我的分支并将其推送到原点。 I have seen the article at How to undo last commit(s) in Git? 我看过如何在Git中撤消最后一次提交的文章 that deals with undoing a local commit, but my problem is that I have pushed the commit to origin. 这涉及撤消本地提交,但我的问题是我已将提交推送到原点。 How to undo this? 如何撤消?

Since you've already pushed to origin, your change has been published for others to see and pull from. 由于您已经推送到原点,因此您的更改已发布给其他人以查看和提取。 Because of this, you probably do not want to rewrite the history. 因此,您可能不想重写历史记录。 So the best command to use is git revert . 所以最好使用的命令是git revert

This creates a new commit that reverses the changes you made. 这将创建一个新的提交,以反转您所做的更改。 Push the new commit and origin will be fixed. 推送新的提交和原点将被修复。

Here is an SO answer that gives more details on this. 这是一个SO答案 ,提供了更多细节。

git reset HEAD^
git push origin +HEAD

should work for you. 应该适合你。 See the git-push and git-reset documentation for more information on why. 有关原因的更多信息,请参阅git-pushgit-reset文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM