git将多个commit合并成一个commit提交

使用场景:在自己的开发分支上开发一个功能提交多次,有多个commit,想将多次提交的commit合并成一个commit,方便代码管理。

例如将最近四次提交的commit合并成一个

1、查看提交历史记录

git log

2、回退到第5个提交,将后面4次提交的内容变为未提交状态

git reset commitID(第五个commit的ID)  //git reset 等同于git reset --mixed

3、提交修改内容

git add .
git commit -m "将前四个commit合并成一个"

4、将代码提交到远程分支

$ git push origin dev_branch
To git@100.2.0.13:rubik-x/rubik-project.git
 ! [rejected]        dev_branch -> dev_branch (non-fast-forward)
error: failed to push some refs to 'git@100.2.0.13:rubik-x/rubik-project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

5、无法提交,因为本地没有远端的4个commit,导致不一致无法推送,因此需要强行推上去

git push -f origin dev_branch

到此完成,是不是很方便。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鱼弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值