Git 删除具体某个提交commit的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。[email protected] 技术讨论群:536739494 https://blog.csdn.net/Nathan1987_/article/details/81605531
1.git log获取commit信息 
2.git rebase -i (commit-id) 
commit-id 为要删除的commit的下一个commit3.编辑文件,将要删除的commit之前的单词改为drop 
4.保存文件退出大功告成 
5.git log查看

比如我的提交历史如下,我现在想删除commit_B,但是不影响commit_B之后的提交历史

commit_C 

commit_B

commit_A

操作方法如下:

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

  1. 首先找到commit_B提交之前的一次提交的commit_A
  2. 执行如下命令

    git rebase -i  commit_A
    

    git rebase .png

  3. commit_B这一行前面的pick改为drop,然后按照提示保存退出

  4. 至此已经删除了指定的commit,可以使用git log查看下
    git push origin HEAD –force 然后推送到远程仓库
    此时 commit_B 就被干掉了,没有影响后面的提交

猜你喜欢

转载自blog.csdn.net/Nathan1987_/article/details/81605531