Git - 撤消推送提交 [英] Git - Undo pushed commits

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

问题描述

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

解决方案

您可以通过以下方式还原单个提交:

git revert 

这将创建一个新的提交,它会还原您指定的提交的更改.请注意,它仅还原该特定提交,而不会还原之后的提交.如果你想恢复一系列提交,你可以这样做:

git revert 

..

它恢复

之后的所有提交,直到并包括 .在某些版本的 git 上,它还会还原 <oldest_commit_hash>,因此请仔细检查该提交是否已还原.您始终可以使用 g reset --hard HEAD~ 删除最新的还原提交(还原最早的提交).

要知道提交的哈希值,您可以使用 git log

查看 git-revert 手册页,了解有关 的更多信息git revert 命令.另外,请查看此答案,了解有关还原提交的更多信息.

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 that come 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 all the commits after <oldest_commit_hash> up to and including <latest_commit_hash>. On some versions of git it also reverts the <oldest_commit_hash>, so double check if that commit gets reverted or not. You can always drop the latest revert commit (which reverts the oldest commit) with g reset --hard HEAD~.

To know the hash of the commit(s) you can use git log

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 - 撤消推送提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆