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

问题描述

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


  • 不在头部或HEAD中

  • 已被推送到远程。
  • 因为如果它不是最新的提交,

      git reset HEAD 

    不起作用。而且因为它已经被推送到远程,所以

      git rebase -i 

      git rebase --onto 

    会导致遥控器出现问题。

    更重要的是,我不想真正修改历史记录。如果代码不好,它就在历史中,并且可以被看到。我只是想在工作副本中,我不介意反向合并提交。



    换句话说,什么是相当于下面的svn命令:

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

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

      svn merge -c -302 ^ / trunk 

    取消302提交,通过添加另一个提交来反向合并来自相应提交的更改。



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



    我们已经暂存了和所有确保提交是完全原子的,你不应该能够轻松地撤销一个或多个这些原子提交?

    解决方案

    使用 git log 确定提交的哈希,然后使用 git revert< commit> 创建一个新的提交来删除这些更改。在某种程度上, git revert git cherry-pick 的反面 - 后者将补丁应用到分支这是缺少它,前者将其从具有它的分支中移除。


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

    • not in the head or HEAD
    • Has been pushed to the remote.

    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
    

    and

    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.

    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
    

    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
    

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

    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?

    解决方案

    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中推送到远程回购的特定提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:25