git 如何将多个提交点合并为一个提交点 commit

文章目录

核心命令

git merge branch2 是将分支branch2的提交点合并到本地当前分支。

而在执行这条命令的时候,加一个选项--squash就表示在合并的时候将多个提交点合并为一个提交点。
git merge --squash branch2

先看squash单词的意思:拥挤,使......拥挤。

以下为git merge --help中查看到的--squash选项的功能:

shell 复制代码
--squash, --no-squash
   Produce the working tree and index state as if a real merge happened (except for the merge information),
   but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git
   commit command to create a merge commit). This allows you to create a single commit on top of the current
   branch whose effect is the same as merging another branch (or more in case of an octopus).

   With --no-squash perform the merge and commit the result. This option can be used to override --squash.

详细使用

模式总结

shell 复制代码
# 1. 先检出目标分支
git checkout <目标分支名>
# 2. 查看当前的本地分支(确认一下分支是否转换成功)
git branch
# 3. 将需合并分支的代码合并到本地分支
git merge -squash<有多个提交点的、需要合并为一个提交点的分支名>
# 4. 查看本地git文件变动(一定会有变动)
git status
# 5. 将新的本地代码变动提交(为一个新的提交点)
git commit -m "提交信息"git push. 推送
# 6. 推送代码到远程服务器
git push

以上6行命令,核心步骤就是3和5。

示例

目标分支/本地当前分支:master

有多个提交点的、想要合并过来的分支:feature/bug_xxx_fix

shell 复制代码
git checkout master
git branch
git merge -squash feature/bug_xxx_fix
git status
git commit -m "fix bug xxx"
git push
相关推荐
DevLoom_7 小时前
macOS 命令行 curl/git 报 SSL 证书错误?eMudhra 事件完整修复指南
git·macos·ssl
keyipatience8 小时前
Git学习(4)Git分布式优势与实战配置全解析
git·学习
SH的全栈笔记10 小时前
敲下 git add 的那一刻,.git 里多了什么
git·后端
正经教主13 小时前
【FDE系列】阶段2:Day 45(up详细版):综合实战 — Docker + Nginx + Git 完整部署与本周收官
人工智能·git·nginx·docker·fde
Change!!1 天前
git小乌龟,切换到新分支处理
git·git切到新分支,旧代码贮藏
LannyChung2 天前
PowerShell 下 git log 中文乱码的完整排查与解决
windows·git
import_random2 天前
[git]本地main,origin/main,远程main(关系2)
git
golang学习记2 天前
Zed Git重大更新:目录级对比支持分栏Diff
git·vscode·zed
阿俊-全栈开发2 天前
LikeShop 单商户高级版二开项目的 Git 分支管理与版本发布规范
git·likeshop·likeshop开源商城·likeshop多商户
努力弹琴的大风天2 天前
TortoiseGit 仓库不显示绿色对号解决方案
git·tortoisegit·图标显示