相关技巧
主页 > 网络编程 > 相关技巧 >

如何使用git reset进行多commit合并

2025-04-03 | 佚名 | 点击:

 

在开发分支下,往往会有多次提交,可能是feature,也可能是bugfix,如果git管理员基于commit进行打tag,这就比较麻烦,所以在打tag之前,最好把相似或者针对同一个feature/bugfix的多次提交进行合并。

工具 git reset

使用git reset

开始合并

首先通过git log找到当前分支的你想要合并的

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

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中。

指向commit

1

git commit a4c4ac595812540ba90ba5a3b7401373259c64bd

重新新增和提交

1

2

3

git add .

git commit -m "compress and merge commit"

git push -f origin <you-branch> #该步骤务必要做

效果如下图

拓展

git rebase 也可以做commit合并,但是需要注意冲突问题,如果发生冲突,需要自己解决之后重新

1

git rebase --continue

原文链接:
相关文章
最新更新