rebase

rebase

一句话说就是git提交记录的”增删改查“

SYNOPSIS

git rebase -i commitId  从某个分支开始进行git提交历史的操作

pick:保留该commit(缩写:p)
reword:保留该commit,但我需要修改该commit的注释(缩写:r)
edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)
squash:将该commit和前一个commit合并(缩写:s)
fixup:将该commit和前一个commit合并,但我不要保留该提交的注释信息(缩写:f)
exec:执行shell命令(缩写:x)
drop:我要丢弃该commit(缩写:d)

DESCRIPTION

git rebase -i commitId 操作从这个commitId开始往后的提交

执行命令后,终端会出现从这个commitId(不包含当前这个commitId)开始往后的所有commitId记录

出现如下记录:

pick d77e853 add b
pick a5258d3 add c
pick 73e0a33 add d

# Rebase 69ef11d..73e0a33 onto 69ef11d (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 <commit> = like "squash", but discard this commit's log message

输入-i进入编辑模式,接下来我们可以按照需求更改pick

reword d77e853 add b
edit a5258d3 add c
squash 73e0a33 add d
fixup 73e0a33 add e
exec 73e0a33 add f
drop 73e0a33 add g

# Rebase 69ef11d..73e0a33 onto 69ef11d (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 <commit> = like "squash", but discard this commit's log message

如此我们esc输入:wq保存即可

当控制台显示Successfully rebased and updated refs/heads/master时表示我们对log操作成功

我们输入git log再次查看即可发现对应变化


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!