撤消已推送到远程存储库的 Git 中的特定提交 [英] Undo a particular commit in Git that's been pushed to remote repos

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

问题描述

撤消特定提交的最简单方法是:

What is the simplest way to undo a particular commit that is:

  • 不在头脑或 HEAD
  • 已推送到远程.

因为如果不是最新的提交,

Because if it is not the latest commit,

git reset HEAD

不起作用.而且因为已经推送到远程了,

doesn't work. And because it has been pushed to a remote,

git rebase -i

git rebase --onto

会导致遥控器出现问题.

will cause some problem in the remotes.

更重要的是,我真的不想修改历史记录.如果有错误的代码,它就在历史中并且可以被看到.我只是希望它在工作副本中出现,我不介意反向合并提交.

More so, I don't want to modify the history really. If there was bad code, it was there in the history and can be seen. I just want it out in the working copy, and I don't mind a reverse merge commit.

换句话说,与以下 svn 命令等效的 Git 是什么:

In other words, what is the Git equivalent of the following svn commands:

svn merge -r 303:295 http://svn.example.com/repos/calc/trunk

通过将这些修订中的所有更改反向合并作为新提交,删除从 295 到 302 的所有更改.

which removes all changes from 295 to 302 by reverse merging all changes in those revisions, as a new commit.

svn merge -c -302 ^/trunk

这会撤销 302 提交,当然是通过添加另一个提交来反向合并来自相应提交的更改.

which undoes the 302 commit, of course by adding another commit that reverse merges the changes from that respective commit.

我认为这应该是一个相当简单的 Git 操作,也是一个相当常见的用例.原子提交还有什么意义?

I thought it should be a fairly simple operation in Git and a fairly common use case. What else is the point of atomic commits?

我们有暂存暂存以及所有确保提交是完美的原子性,难道您不应该能够轻松撤消这些原子性提交中的一个或多个吗?

We have staging stashing and all to ensure the commits are perfectly atomic, shouldn't you be able to undo one or more of those atomic commits easily?

推荐答案

确定提交的hash,使用git log,然后使用git revert 创建一个删除这些更改的新提交.在某种程度上,git revertgit cherry-pick 的反面——后者将补丁应用到一个缺少它的分支,前者从一个分支中删除它有.

Identify the hash of the commit, using git log, then use git revert <commit> to create a new commit that removes these changes. In a way, git revert is the converse of git cherry-pick -- the latter applies the patch to a branch that's missing it, the former removes it from a branch that has it.

这篇关于撤消已推送到远程存储库的 Git 中的特定提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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