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
相关推荐
齐 飞2 小时前
idea中git误操作撤回git reset --hard ‘HEAD@{1}‘
java·git·intellij-idea
长成一棵参天树5 小时前
React15 vs React16 核心区别
git·vscode
驭渊的小故事9 小时前
Git 基础操作与对象观察
git
Hvitur10 小时前
Gitea 版本控制服务端【Red Hat 离线安装】
git
flytalei11 小时前
逐浪笔记 GitOps 实战:Jenkins 构建、Argo CD 同步与 Git 回滚
笔记·git·jenkins
熊出没12 小时前
CommitLoom 使用教程:在 IntelliJ IDEA 中自动生成 Git 提交信息
java·git·intellij-idea
IOT那些事儿1 天前
Git报错:Could not get HEAD hash
git·hash·head
杜哥无敌1 天前
Git Bash + acme.sh 实现 SSL 证书自动续签(完整指南)
git·bash·ssl
nunumaymax1 天前
Git教程
git
阿萨德528号1 天前
IDEA 项目 SVN 配置消失、版本控制变成 Git 且无 VCS 菜单的解决办法
git·svn·intellij-idea