git rebase --onto 删除commit
Git 管理代码,如果某个分支commit 了多次提交,但是发现中间一些commit提交想删除它。怎么操作呢?看官方例子。

备注:topicA 代表分支名称
topicA~5 代表改分支从HEAD向后数5个,这里就是F commit
topicA~3 代表改分支从HEAD向后数3个,这里就是H commit
git rebase --onto topicA~5 topicA~3 topicA
所以上面命令是把F到H(不包含它)的commit 删除。
例子
git init ./
touch.exe file1.c && git add file1.c && git commit -m "Add file1.c"
touch.exe file2.c && git add file2.c && git commit -m "Add file2.c"
touch.exe file3.c && git add file3.c && git commit -m "Add file3.c"
touch.exe file4.c && git add file4.c && git commit -m "Add file4.c"
touch.exe file5.c && git add file5.c && git commit -m "Add file5.c"
touch.exe file6.c && git add file6.c && git commit -m "Add file6.c"
执行Git log
commit 历史如下
执行 git rebase --onto master~5 master~3 master
commit 历史如下

提示: 可以直接指定具体的 commit ID 去删除
![]()
779

被折叠的 条评论
为什么被折叠?



