Git要用才會用 #3 合併code (rebase -i squash)
有時候寫 code 的過程很亂,一個功能可能有十幾個 commit,有些 commit 想要先合併,就可以用 squash 合併 code
rebase -i
rebase -i
是互動模式,有很多種功能可以用
這篇介紹的是其中的squash <commit>
,可以合併好幾個 commit
rebase -i 可用的功能:
# 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.
rebase 第一個 commit
做 rebase -i 的時候,必須要回到"要處理的 commit" 的前一個 commit。
那如果要改的 commit 就是第一個 commit 怎麼辦?那就要用以下指令
git rebase -i --root
📋 文件
Share