git合并commit记录

第一步

git rebase -i HEAD~ 数字(要合并的数量)

 如(合并数量为3个时):

git rebase -i HEAD~3

  第二步

注意:

如果是在vscode里面自动打开文件,则直接在vscode里面进行修改;

如果是在git里面则会进入编辑区,按i进行编辑即可,以下是需要编辑的内容。

保留第一行的pick,其余行改为squash

// 原来的代码
git a6a378d feat: 1
git 59b790d feat: 2
git af5c9a2 feat: 3
// 修改后的代码
git a6a378d feat: 1
squash 59b790d feat: 2
squash af5c9a2 feat: 3

 第三步

注意:

若在vscode中则保存好修改的文件后退出,退出后会自动在vscode里面打开另外一个文件;

若在git中则保存退出编辑模式(按esc后按:键再在最下方输入wq后回车退出),退出后会进入编辑信息页面

把不需要的commit注释掉

//原来的代码
# This is a combination of 2 commits.
# This is the 1st commit message:

feat: 1

# This is the commit message #2:

feat: 2

# This is the commit message #3:

feat: 3
//修改后的代码
# This is a combination of 2 commits.
# This is the 1st commit message:

#feat: 1

# This is the commit message #2:

#feat: 2

# This is the commit message #3:

feat: 3

 第四步(关键一步)

强制push上去:

git push -f origin + 分支名

git remote看一下是否为origin,这里举例用的是origin,不是的话就替换一下。

$ git remote
origin

 如(分支名为feat-edit时):

git push -f origin feat-edit

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值