本文介绍了Git - 撤消提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程存储库中有一个项目,与本地存储库(开发)和服务器(prod)同步。我一直在做一些已经被推送到远程并从服务器拉出来的改变。现在,我想撤销这些更改。所以我可以在更改之前提交 git checkout 到提交并提交新的更改,但我猜测将会有问题将它们再次推送到远程。任何关于我应该如何进行的建议?

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. Any suggestion on how should I proceed?

推荐答案

您可以将个别提交归还给:

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.

请参阅以获取有关 git revert 命令。有关还原提交的更多信息,请参阅。

Look at the git-revert man page for more information about the git revert command. Also look at this answer for more information about reverting commits.

这篇关于Git - 撤消提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:33