【Git】merge 分支时合并多个 commit 注释

文章目录

我们开发需求的时候,开发分支可能会有多个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)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一颗不甘坠落的流星

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

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

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

打赏作者

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

抵扣说明:

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

余额充值