git合并多个commit为一个

注意:合并的时候尽量不要合并其他人的提交,因为合并之后不会保留,更新完之后其他人的代码会有冲突,需要删了重建

步骤一:查看commit提交记录 (复制需要合并的id)

git log --oneline

--oneline参数,代表将每个commit压缩成一行,只显示commitID和commit message的第一行

步骤二:执行rebase -i 打开交互

git rebase -i <commit ID>

例如:git rebase -i d5d1335

步骤三:根据需要改写命令,把pick改为s/squash

pick a50f132 第2次commit

s 73c98f9 第3次commit

s 25d5ae5 第4次commit

s d5ace53 第5次commit

# Rebase d5d1335..d5ace53 onto d5d1335 (4 command)

#

# Commands:

# p, pick <commit> = use commit

# r, reword <commit> = use commit, but edit the commit message

# e, edit <commit> = use commit, but stop for amending

# s, squash <commit> = use commit, but meld into previous commit

# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous

# commit's log message, unless -C is used, in which case

# keep only this commit's message; -c is same as -C but

# opens the editor

# x, exec <command> = run command (the rest of the line) using shell

# b, break = stop here (continue rebase later with 'git rebase --continue')

# d, drop <commit> = remove commit

# l, label <label> = label current HEAD with a name

# t, reset <label> = reset HEAD to a label

# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]

# create a merge commit using the original merge commit's

# message (or the oneline, if no original merge commit was

# specified); use -c <commit> to reword the commit message

步骤四:强制推送

git push -f

如果遇到错误需要先解决冲突:git status

最后有个保险操作:git reset

为什么要执行这个操作?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值