我需要弹出一个“中间”在我的主分支中提交。我该怎么做? [英] I need to pop up and trash away a "middle" commit in my master branch. How can I do it?

查看:101
本文介绍了我需要弹出一个“中间”在我的主分支中提交。我该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在下面的master分支中,我只需要提交af5c7bf16e6f04321f966b4231371b21475bc4da,这是由于之前的rebase而导致的第二个提交:

  commit 60b413512e616997c8b929012cf9ca56bf5c9113 
作者:Luca G. Soave< luca.soave@gmail.com>
日期:4月12日星期二23:50:15 2011 +0200

添加通用配置/初始化程序/ omniauth.example.rb

提交af5c7bf16e6f04321f966b4231371b21475bc4da
作者:Luca G. Soave< luca.soave@gmail.com>
日期:星期五4月22日00:15:50 2011 +0200

显示github用户信息(如果已登录)

提交e6523efada4d75084e81971c4dc2aec621d45530
作者:Luca G. Soave< luca.soave@gmail.com>
日期:星期五4月22日17:20:48 2011 +0200

在blueprint布局中添加多个.container

提交414ceffc40ea4ac36ca68e6dd0a9ee97e73dee22
作者:Luca G 。Soave< luca.soave@gmail.com>
日期:四月21日星期四19:55:57 2011 +0200

add%h1 Fantastic Logo + .right for'用Github'登录



我需要mantain第一次提交60b413512e616997c8b929012cf9ca56bf5c9113,

  • 第三次提交e6523efada4d75084e81971c4dc2aec621d45530和
  • 上次提交414ceffc40ea4ac36ca68e6dd0a9ee97e73dee22



  • 扔掉只是第二次提交 af5c7bf16e6f04321f966b4231371b21475bc4da



    我该怎么做?
    在此先感谢
    Luca

    解决方案

    Rebase 还原是选项。 Rebase实际上会从历史记录中删除提交,所以它看起来像第二次提交从未存在过。如果您已将主分支推送到任何其他回购站,这将成为问题。如果你尝试在这种情况下推迟rebase,git会给你一个拒绝非快进合并错误。

    Revert是正确的解决方案,当分支已与其他回购共享。 git revert af5c7bf16 会做出一个新的提交,简单地反转af5c7bf16引入的更改。这样,历史不会被重写,您可以清楚地记录错误,其他回购将接受推送。



    以下是擦除的一个好方法: git rebase -i< commit> ^
    这会将您带到要删除的提交之前的提交。交互式编辑器将向您显示所有提交到该点的提交列表。你可以选择,压扁等。在这种情况下,删除要删除并保存文件的提交行。 Rebase将完成其工作。


    For example, in the following master branch, I need to trash just the commit af5c7bf16e6f04321f966b4231371b21475bc4da, which is the second due to previous rebase:

    commit 60b413512e616997c8b929012cf9ca56bf5c9113
    Author: Luca G. Soave <luca.soave@gmail.com>
    Date:   Tue Apr 12 23:50:15 2011 +0200
    
        add generic config/initializers/omniauth.example.rb
    
    commit af5c7bf16e6f04321f966b4231371b21475bc4da
    Author: Luca G. Soave <luca.soave@gmail.com>
    Date:   Fri Apr 22 00:15:50 2011 +0200
    
        show github user info if logged
    
    commit e6523efada4d75084e81971c4dc2aec621d45530
    Author: Luca G. Soave <luca.soave@gmail.com>
    Date:   Fri Apr 22 17:20:48 2011 +0200
    
        add multiple .container at blueprint layout
    
    commit 414ceffc40ea4ac36ca68e6dd0a9ee97e73dee22
    Author: Luca G. Soave <luca.soave@gmail.com>
    Date:   Thu Apr 21 19:55:57 2011 +0200
    
        add %h1 Fantastic Logo + .right for 'Sign in with Github'
    

    I need to mantain

    • the First commit 60b413512e616997c8b929012cf9ca56bf5c9113,
    • the Third commit e6523efada4d75084e81971c4dc2aec621d45530 and
    • the Last commit 414ceffc40ea4ac36ca68e6dd0a9ee97e73dee22

    "throwing away" just the Second commit af5c7bf16e6f04321f966b4231371b21475bc4da

    How can I do that? Thanks in advance Luca

    解决方案

    Rebase or revert are the options. Rebase will actually remove the commit from the history so it will look like that second commit never existed. This will be a problem if you've pushed the master branch out to any other repos. If you try to push after a rebase in this case, git will give you a reject non fast-forward merges error.

    Revert is the correct solution when the branch has been shared with other repos. git revert af5c7bf16 will make a new commit that simply reverses the changes that af5c7bf16 introduced. This way the history is not rewritten, you maintain a clear record of the mistake, and other repos will accept the push.

    Here's a good way to erase: git rebase -i <commit>^ That takes you to the commit just before the one you want to remove. The interactive editor will show you a list of all the commits back to that point. You can pick, squash, etc. In this case remove the line for the commit you want to erase and save the file. Rebase will finish its work.

    这篇关于我需要弹出一个“中间”在我的主分支中提交。我该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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