当前位置: 首页 > news >正文

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

文章目录

    • 核心命令
    • 详细使用
      • 模式总结
      • 示例

核心命令

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

先看squash单词的意思:拥挤,使……拥挤。
在这里插入图片描述

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

--squash, --no-squashProduce 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 gitcommit command to create a merge commit). This allows you to create a single commit on top of the currentbranch 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.

详细使用

模式总结

# 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

git checkout master
git branch
git merge -squash feature/bug_xxx_fix
git status
git commit -m "fix bug xxx"
git push
http://www.lryc.cn/news/316836.html

相关文章:

  • [C语言] 数据存储
  • LoadBalancer负载均衡服务调用
  • YoloV8实战:YoloV8-World应用实战案例
  • Python 导入Excel三维坐标数据 生成三维曲面地形图(体) 5-1、线条平滑曲面且可通过面观察柱体变化(一)
  • cmake初识
  • Swift 入门学习:集合(Collection)类型趣谈-下
  • nova 12 LTPO来了!LTPO动态自适应刷新率屏120Hz体验更流畅 ,1Hz阅读更省电
  • 【rk3368 android6.0 恢复出厂设置功能】
  • 闲聊电脑(7)常见故障排查
  • Vim 编辑器|批量注释与批量取消注释
  • Android 使用AIDL HAL
  • C++的一些基础语法
  • mysql 技术100问?
  • APK漏洞扫描工具
  • ReactNative项目构建分析与思考之react-native-gradle-plugin
  • LeetCode454 四数相加
  • Kafka消费者重平衡
  • 【线代基础】张量、向量、标量、矩阵的区别
  • 用chatgpt写论文重复率高吗?如何降低重复率?
  • 字节跳动也启动春季校园招聘了(含二面算法原题)
  • 二,几何相交---4,BO算法---(3)数据结构
  • 中间件MQ面试题之Kafka
  • Prometheus 安装部署
  • 龙芯杯赛道-学习过程记录
  • 76. 最小覆盖子串-力扣hot100(C++)
  • vue的生命周期有那些
  • OpenStack安装步骤
  • 如何借助CRM系统获得直观的业务洞察?CRM系统图表视图解析!
  • 制作图片马:二次渲染(upload-labs第17关)
  • XGB-20:XGBoost中不同参数的预测函数