Git 刪除某次提交(某個commit)的方法


例如我的提交歷史如下

commit 58211e7a5da5e74171e90d8b90b2f00881a48d3a
Author: test <test@36nu.com>
Date:   Fri Sep 22 20:55:38 2017 +0800

    add d.txt

commit 0fb295fe0e0276f0c81df61c4fd853b7a000bb5c
Author: test <test@36nu.com>
Date:   Fri Sep 22 20:32:45 2017 +0800

    add c.txt

commit 7753f40d892a8e0d14176a42f6e12ae0179a3210
Author: test <test@36nu.com>
Date:   Fri Sep 22 20:31:39 2017 +0800

    init

假如要刪除備注為add c.txt commit為0fb295fe0e0276f0c81df61c4fd853b7a000bb5c的這次提交

首先找到此次提交之前的一次提交的commit7753f40d892a8e0d14176a42f6e12ae0179a3210
執行如下命令【執行 rebase 時會可能遇到沖突,解決沖突不在本文描述范圍
git rebase -i 7753f40
彈出如下界面

0fb295f這一行前面的pick改為drop,然后按照提示保存退出
至此已經刪除了指定的commit,可以使用git log查看下

參考:
http://www.36nu.com/post/275
https://www.cnblogs.com/zqunor/p/8620335.html
https://blog.csdn.net/qq_41988504/article/details/105977374


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM