git删除某次提交(某个commit)的方法

例如我的提交历史如下

commit 58211e7a5da5e74171e90d8b90b2f00881a48d3a
Author: test <[email protected]>
Date:   Fri Sep 22 20:55:38 2017 +0800

    add d.txt

commit 0fb295fe0e0276f0c81df61c4fd853b7a000bb5c
Author: test <[email protected]>
Date:   Fri Sep 22 20:32:45 2017 +0800

    add c.txt

commit 7753f40d892a8e0d14176a42f6e12ae0179a3210
Author: test <[email protected]>
Date:   Fri Sep 22 20:31:39 2017 +0800

    init

假如要删除备注为add c.txt commit为0fb295fe0e0276f0c81df61c4fd853b7a000bb5c的这次提交

  1. 首先找到此次提交之前的一次提交的commit7753f40d892a8e0d14176a42f6e12ae0179a3210
  2. 执行如下命令
    git rebase -i  7753f40
    
    弹出如下界面(原图丢失,下图类似)
  3. 0fb295f这一行前面的pick改为drop,然后按照提示保存退出
  4. 至此已经删除了指定的commit,可以使用git log查看下

猜你喜欢

转载自blog.csdn.net/faithmy509/article/details/81271436