当你想把git 的多次提交记录合并为一次时,可以使用git rebase.
1、先查历史提交记录
git log --pretty=format:'%h: %cd %s' --graph
* f2bb0dd: Wed Feb 8 11:14:44 2023 +0800 add reflector
* 7421ce5: Tue Feb 7 00:01:45 2023 +0800 add list watch
* b4c80af: Mon Jan 30 23:21:51 2023 +0800 add first
2、git rebase -i
git rebase -i b4c80af
为前开后闭区间,如想合并上面前两次的提交记录,需要以第三行的为基础
3、执行后进入如下:顺序与git log 相反
pick 7421ce5 add list watch
pick f2bb0dd add reflector
# Rebase b4c80af..6fd7c96 onto b4c80af (1 command)
#
# 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 <commit> = like "squash", but discard this commit's log message
# 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.
4、如想合并这两次的提交为1次,可以修改hash值前的命令:
pick 7421ce5 add list watch
s f2bb0dd add reflector
4、 按 I 修改 ,ESC退出, :wq保存
网友评论