文章目录
我们开发需求的时候,开发分支可能会有多个commit信息,等合并到主分支master的时候,会造成commit累赘,下面这种方法就能解决这个问题
- 比如当前开发分支
test02
,有 2 条commit
记录,git log
查看: - 但是这两次提交都是针对一个功能的,就没必要都合并到主分支上
➜ git:(test02) git log -2
commit 6f53d8d8d4d570082e580554b68d36707f50421d
Author: 流星
Date: Mon Feb 13 16:45:21 2023 +0800
chore: 修改登录功能
commit 832f3e68516de9162d0f03bc23bdbb6f86297b9d
Author: 流星
Date: Mon Feb 13 15:51:27 2023 +0800
feat: 添加登录功能
(END)
- 首先先切换到主分支
test01
上去
➜ git:(test02) git checkout test01
Switched to branch 'test01'
- 然后
merge
分支时,添加一个--squash
字段
➜ git:(test01) git merge test02 --squash
Updating b1d603ed0..d950712fc
Fast-forward
Squash commit -- not updating HEAD
packages/pages/src/table/index.vue | 1 +
1 file changed, 1 insertion(+)
- 这时候 2 次修改的代码就会回到暂存区
➜ git:(test01) ✗ git status
On branch test01
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: packages/pages/src/table/index.vue
- 然后重新提交合并后的注释:
➜ git:(test01) ✗ git commit -m 'feat: 添加登录功能'
→ No staged files match any configured task.
✔ Preparing lint-staged...
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Cleaning up temporary files...
--------------------- git add ------------------
Nothing specified, nothing added.
hint: Maybe you wanted to say 'git add .'?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"
---------------------- done --------------------
[lstest01 832f3e685] feat: 添加登录功能
1 file changed, 1 insertion(+)
- 这时候
test01
分支就没有test02
分支那么多累赘的commit
注释了
➜ git:(test01) git log
commit 832f3e68516de9162d0f03bc23bdbb6f86297b9d (HEAD -> test01)
Author: 流星
Date: Mon Feb 13 15:51:27 2023 +0800
feat: 添加登录功能
(END)