本文翻译自:Git - Undo pushed commits
I have a project in a remote repository, synchronized with a local repository (development) and the server one (prod). 我在远程存储库中有一个项目,与本地存储库(开发)和服务器(产品)同步。 I've been making some commited changes already pushed to remote and pulled from the server. 我一直在进行一些已提交的更改,这些更改已推送到服务器并已从服务器拉出。 Now, I want to undo those changes. 现在,我要撤消那些更改。 So I could just git checkout
to the commit before the changes and commit the new changes, but I'm guessing that there will be problems to push them again to remote. 因此,我可以在更改之前将git checkout
到提交并提交新更改,但是我猜测将它们再次推送到远程将存在问题。 Any suggestion on how should I proceed? 关于如何进行的任何建议?
#1楼
参考:https://stackoom.com/question/1XAqk/Git-撤消推送的提交
#2楼
You can revert individual commits with: 您可以使用以下方法还原单个提交:
git revert <commit_hash>
This will create a new commit which reverts the changes of the commit you specified. 这将创建一个新的提交,该提交将还原您指定的提交的更改。 Note that it only reverts that specific commit, and not commits after that. 请注意,它仅还原特定的提交,之后不提交。 If you want to revert a range of commits, you can do it like this: 如果要还原一定范围的提交,可以这样进行:
git revert <oldest_commit_hash>..<latest_commit_hash>
It reverts the commits between and including the specified commits. 它还原指定提交之间(包括指定提交)的提交。
Look at the git-revert man page for more information about the git revert
command. 查看git-revert手册页以获取有关git revert
命令的更多信息。 Also look at this answer for more information about reverting commits.