git合并多个commit & 压缩合并 git rebase pick squash
实践:
需求:
cid0
cid1
cid2
将cid1、cid2压缩到cid0
操作:
git rebase -i cid0
pick cid0 msg0
pick cid1 msg1
pick cid2 msg2
# Rebase cid0..cid2 onto cid0 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# create a merge commit using the original merge commit's
# message (or the oneline, if no original merge commit was
# specified); use -c <commit> to reword the commit message
# u, update-ref <ref> = track a placeholder for the <ref> to be updated
# to this position in the new commits. The <ref> is
# updated at the end of the rebase
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
--->
pick cid0 msg0
s cid1 msg1
s cid2 msg2
编辑新的msg
# This is a combination of 3 commits.
# This is the 1st commit message:
msg0
# This is the commit message #2:
msg1
# This is the commit message #3:
msg2
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Mon Sep 9 12:43:30 2024 +0800
#
# interactive rebase in progress; onto d705fe20
# Last commands done (3 commands done):
# squash cid1 msg1
# squash cid2 msg2
# No commands remaining.
git合并多个commit & 压缩合并 - 简书 https://www.jianshu.com/p/4dfefdc94532