您当前的位置: 首页 >  git

咸鱼弟

暂无认证

  • 6浏览

    0关注

    165博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

咸鱼弟 发布时间:2020-02-17 22:20:19 ,浏览量:6

使用场景:在自己的开发分支上开发一个功能提交多次,有多个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

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

关注
打赏
1663644285
查看更多评论
立即登录/注册

微信扫码登录

0.0818s