屏幕快照 2020-06-06 下午10.10.04.png
如圖所示我們有時(shí)候在本地修修改改成多個(gè)提交披摄,想合并成一個(gè)在推到遠(yuǎn)程的時(shí)候需要用到git rebase
testdeMBP:DEMO test$ git rebase -i HEAD~5
HEAD~5表示將最新的提交往后數(shù)幾個(gè)提交合并壳贪,然后出現(xiàn)如下頁面
pick 0f32607 其他: 第1次提交
pick 541c8fc 其他: 第2次提交
pick 06279bc 其他: 第3次提交
pick 714496d 其他: 第4次提交
pick 1a56b7f 其他: 第5次提交
# Rebase ed28fcf..1a56b7f onto ed28fcf (5 commands)
#
# Commands:
# p, pick <commit> =保留該commit(縮寫:p)
# r, reword <commit> = 保留該commit槽惫,但我需要修改該commit的注釋(縮寫:r)
# e, edit <commit> =但我要停下來修改該提交(不僅僅修改注釋)(縮寫:e)
# s, squash <commit> = 將該commit和前一個(gè)commit合并(縮寫:s)
# f, fixup <commit> = 將該commit和前一個(gè)commit合并,但我不要保留該提交的注釋信息(縮寫:f)
# x, exec <command> = shell 執(zhí)行shell命令(縮寫:x)
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = 我要丟棄該commit(縮寫:d)
# 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.
根據(jù)說明我將在上面的信息修改成如下然后wq保存
pick 0f32607 其他: 第1次提交
s 541c8fc 其他: 第2次提交
s 06279bc 其他: 第3次提交
s 714496d 其他: 第4次提交
s 1a56b7f 其他: 第5次提交
上面的意思就是把第2次到第5次的提交都合并到第一次提交上
然后wq保存退出后是注釋修改界面:
# This is a combination of 5 commits.
# This is the 1st commit message:
其他: 第1次提交
# This is the commit message #2:
其他: 第2次提交
# This is the commit message #3:
其他: 第3次提交
# This is the commit message #4:
其他: 第4次提交
# This is the commit message #5:
其他: 第5次提交
將合并的提交的log編輯成一行
# This is a combination of 5 commits.
# This is the 1st commit message:
其他: 第1次提交;第2次提交;第3次提交;第4次提交;第5次提交
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Sat Jun 6 22:07:17 2020 +0800
#
# interactive rebase in progress; onto ed28fcf
# Last commands done (5 commands done):
# squash 714496d 其他: 第4次提交
# squash 1a56b7f 其他: 第5次提交
# No commands remaining.
# You are currently rebasing branch 'dev' on 'ed28fcf'.
#
# Changes to be committed:
# modified: README.md
#
最終多個(gè)提交合并成了一個(gè)可以推到遠(yuǎn)端或者合并到其他分支去了
屏幕快照 2020-06-06 下午10.29.39.png
當(dāng)然git rebase不只是合并提交,還可以丟棄提交更改提交信息等等,具體可以根據(jù)注釋信息進(jìn)行靈活更改