type
status
date
slug
summary
tags
category
icon
password
要将当前分支与master分支的所有差异合并为一个单独的commit,你可以使用以下方法:
方法一:使用交互式rebase和squash
- 首先确保你的工作目录是干净的(没有未提交的更改)
- 获取最新的master分支代码:
- 找出当前分支从master分叉的点:
- 开始交互式rebase:
- 在打开的编辑器中,保留第一个commit为"pick",将其余所有commit前的"pick"改为"squash"或"s"(这将把它们合并到第一个commit中)
- 保存并退出编辑器
- Git会提示你编辑新的合并commit的消息,完成后保存退出
方法二:使用reset和单个commit
- 确保工作目录是干净的
- 创建当前状态的临时备份:
- 重置到master分支:
- 将当前分支的所有更改作为一个新commit提交:
- 删除临时备份分支(可选):
方法三:使用cherry-pick
- 创建一个新的临时分支:
- 将原分支的所有更改cherry-pick到新分支:
- 删除原分支并重命名临时分支:
完成上述任一方法后,你的当前分支与master分支的差异将只包含一个commit。
- Author:Ximou Zhao
- URL:https://ximouzhao.com/article/20e4b0ac-588b-80a0-a9f4-e86ba8f0f33e
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!