rebase的兩大用處:
- 從上游分支獲取最新commit信息略荡,并有機(jī)的將當(dāng)前分支和上游分支進(jìn)行合并。
git rebase 變基分析:http://blog.chinaunix.net/uid-27714502-id-3436696.html
參考上面鏈接,稍后做總結(jié)
- 刪除無(wú)用的中間 commit 記錄 參考文章](http://www.reibang.com/p/964de879904a))
前言: rebase 命令刪除中間的無(wú)用 commit 記錄蛤售,意味著至少保留首尾兩個(gè) commit
# 從 commit_id 開(kāi)始到最后 commit 進(jìn)行 rebase烘豹,進(jìn)入編輯模式
$ git rebase -i [commit_id]
# 進(jìn)入到編輯模式會(huì)看到可編輯的條目, 排列順序由 commit 的提交先后 從上而下胆敞。
# 編輯模式中分兩部分內(nèi)容着帽, 上半部分可編輯,是要執(zhí)行的指令移层,下半部分是指令的注釋仍翰。
# 指令部分由 指令名稱、 commit hash 和 commit mesage 組成
# 指令名稱目前只需要知道 pick 和 squash 這兩個(gè)指令观话,具體解釋見(jiàn)下邊的指令注釋
pick 2da3fdf add commit message_2
pick 7efd141 add this is last commit
# Rebase 6506966..7efd141 onto 6506966 (1 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
#
# 調(diào)整好要合并或者修改的條目之后予借, 執(zhí)行 :wq 命令,git會(huì)執(zhí)行合并或改名操作匪燕,執(zhí)行之后會(huì)再次進(jìn)入 vi 編輯頁(yè)面蕾羊。
# 該編輯頁(yè)面非注釋部分就是幾次的commit message , 我們要做的就是要將這些內(nèi)容修改成新的 commit message
# 輸入 wq 保存,幾次 commit 就已經(jīng)合并了帽驯。
# 查看 log 信息可進(jìn)行驗(yàn)證
注意事項(xiàng)
在 rebase 的過(guò)程中有操作失誤龟再, 可以使用 git rebase --abort 來(lái)撤銷修改,回到?jīng)]有開(kāi)始操作合并之前的狀態(tài)尼变。