场景:
远程仓库的时间线从前到后一共有6个提交,分别为A B C D E F(A是远程仓库第一个提交)
现在需要实现删除B C D的提交记录,让远程仓库的时间线上只出现 A E F。
操作方法
1、git rebase --onto commit-id^ commit-id (具体用哪个comiit-id 看下文举例)
2、处理好rebase之后的冲突(不一定会发生),处理完冲突之后,本地分支上已经没有了BCD的记录。
3、git push --force 强制推送到远程仓库
举例实操:
A (commit-id -> af65e5eff383ec5d36d530283ab5ec55fdeb87a5)
B
C
D (commit-id -> ef499db0cbfc959377c5e249e5f0b0d013623898)
E
F
需要删除 B C D的记录
那么需要 git rebase --onto (hash for A)^ (hash for D)
命令行输入
1、git rebase --onto af65e5eff383ec5d36d530283ab5ec55fdeb87a5^ ef499db0cbfc959377c5e249e5f0b0d013623898
2、手动处理冲突
3、git push --force
注意:
A作为远程仓库的第一个提交,这条提交记录无法被删除。
完结。
同步更新到自己的语雀
https://www.yuque.com/diracke...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。