git rebase将多次提交合为一次

1、 查看提交历史
git log 

2、找到你想合并到哪一个commit_id 
如:
commit_1
commit_2
commit_3
commit_4
commit_5

3、你想合并前4次,则输入:
git rebase -i commit_5

此时你预设的编辑器将会打开一个文档,其中含有如下类似内容:

pick fc62e55 fix bugs
pick 9824bf4 fixed bugs
pick 21d80a5 add file
pick 76b9da6 add file

# Rebase f408319..b04dc3d onto f408319# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

4、将文档中第2行到第4行的pick 改为s, 保存、退出。

pick fc62e55 fix bugs
s 9824bf4 fixed bugs
s 21d80a5 add file
s 76b9da6 add file

# Rebase f408319..b04dc3d onto f408319# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

5、此时你预设的编辑器将会打开一个文档,其中会包含你提交时的注释,删除后3次,保留最新一次,保存、退出。

6、推送到远程。

git push -f origin branch_name

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值