文章目录
- commit 991b88a8be945952c5b83b9e290f65d05c9d0bdd Author: R1 <123456@abc.com> Date: Wed Sep 16 10:42:51 2020 +0800 bugfix3 commit 70dcd0415713d5e17a7b2ff8eaf2280dd076657c Author: R2 <123457@abc.com> Date: Mon Sep 14 17:19:54 2020 +0800 bugfix2 commit a4c4ac595812540ba90ba5a3b7401373259c64bd Author: R1 <123456@abc.com> Date: Tue Aug 25 17:37:07 2020 +0800 bugfix1 以上我想把所有的commit都要合并到a4c4ac595812540ba90ba5a3b7401373259c64bd中。
- git commit a4c4ac595812540ba90ba5a3b7401373259c64bd
- git add . git commit -m “compress and merge commit” git push -f origin <you-branch> #该步骤务必要做
目录
- 工具 git reset
- 开始合并
- 首先通过git log找到当前分支的你想要合并的
- 指向commit
- 重新新增和提交
- 效果如下图
- 拓展
- 总结
在开发分支下,往往会有多次提交,可能是feature,也可能是bugfix,如果git管理员基于commit进行打tag,这就比较麻烦,所以在打tag之前,最好把相似或者针对同一个feature/bugfix的多次提交进行合并。
使用git reset
commit 991b88a8be945952c5b83b9e290f65d05c9d0bdd
Author: R1 <123456@abc.com>
Date: Wed Sep 16 10:42:51 2020 +0800
bugfix3
commit 70dcd0415713d5e17a7b2ff8eaf2280dd076657c
Author: R2 <123457@abc.com>
Date: Mon Sep 14 17:19:54 2020 +0800
bugfix2
commit a4c4ac595812540ba90ba5a3b7401373259c64bd
Author: R1 <123456@abc.com>
Date: Tue Aug 25 17:37:07 2020 +0800
bugfix1
以上我想把所有的commit都要合并到a4c4ac595812540ba90ba5a3b7401373259c64bd中。
git commit a4c4ac595812540ba90ba5a3b7401373259c64bd
git add .
git commit -m "compress and merge commit"
git push -f origin <you-branch> #该步骤务必要做

git rebase 也可以做commit合并,但是需要注意冲突问题,如果发生冲突,需要自己解决之后重新
git rebase --continue
以上为个人经验,希望能给大家一个参考,也希望大家多多支持风君子博客。
您可能感兴趣的文章:
- Git版本回退之reset和revert使用详解
- git中reset和revert区别小结
- git 报错:OpenSSL SSL_read: Connection was reset, errno 10054 解决方法
- Git恢复之前版本的三种方法之reset、revert、rebase详解