本人也是最近2周才开始使用git,有些也理解不到位,在工作中实操之后记录下来,工作环境linux ubuntu。
变基时有六个命令可用:
pick
pick只是意味着包括提交。重新进行命令时,重新安排pick命令的顺序会更改提交的顺序。如果选择不包括提交,则应删除整行。
reword
该reword命令与相似pick,但是使用后,重新设置过程将暂停并为您提供更改提交消息的机会。提交所做的任何更改均不受影响。
edit
如果您选择edit提交,则将有机会修改提交,这意味着您可以完全添加或更改提交。您还可以进行更多提交,然后再继续进行变基。这使您可以将大型提交拆分为较小的提交,或者删除在提交中所做的错误更改。
squash
该命令使您可以将两个或多个提交合并为一个提交。提交被压缩到其上方的提交中。Git使您有机会编写描述这两个更改的新提交消息。
fixup
这类似于squash,但是要合并的提交已丢弃其消息。提交仅合并到其上方的提交中,并且较早提交的消息用于描述这两个更改。
exec
命令是:git rebase -i HEAD~n
其中n代表的是将要n条commit log合并为一个commit log,然后进入一个界面,按i进行vim编辑
pick 8b485bc add 4
pick a75ed75 add 5
# Rebase 63ce9fc..a75ed75 onto 63ce9fr (2 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~
~
下面注释的是提示,我们不需要管,只要专注前两行就行
然后,第二行的pick改为s,表示将第二个commit合并到第一个comit中。
如果需要修改commit信息,可以进行修改,然后修改注释,最后保存退出。