git如何保留做出的修改,但是删除多余的提交历史

在test分支写了一些东西,提交了很多次,像这样:

$ git log --oneline
c7c3a2a (HEAD -> test, origin/test) remove comment
873555f test8
dc0de8a test7
27339a3 test6
a8e94e6 test5
cc4b799 test4
6ff8c72 test3
ab68e0f test2
e8c6efb test1
0ea5853 add style
d6272fa init

然后不小心给merge到了master分支上,还给push了,结果master分支的commit log变的很乱。
现在希望保留做出的修改,但是删除多余的提交历史,该怎么办呢?

$ git rebase -i 0ea5853

进入交互式变基,然后把要删去的提交历史前的pick改为squash,保存并推出,然后git还会让你填写一下提交历史
然后

git push -f

猜你喜欢

转载自blog.csdn.net/dongdaxiaopenyou/article/details/88218618