git rebaseって結局なんなの(2)
前回の記事では割愛した、commitの改変についてもう少し詳細に見ていこうと思います。
対話的なrebase
git rebase -i commit履歴 を実行すると対話的にrebaseを行うモードに移行します。
対話的rebaseモードでは、指定したcommit以降のcommit履歴が古いものから順に表示されます。
commitサンプル
A B C D
この履歴に対して、git rebase -i D を実行すると
pick C pick B pick A
このような画面が表示されます。 それぞれのcommitとこれから適用する操作の一覧です。
下のほうには以下のように適用可能な操作の説明が記載されています。
# These lines can be re-ordered; they are executed from top to bottom. # # d, drop = remove commit # x, exec = run command (the rest of the line) using shell # f, fixup = like "squash", but discard this commit's log message # s, squash = use commit, but meld into previous commit # e, edit = use commit, but stop for amending # r, reword = use commit, but edit the commit message # p, pick = use commit
操作名 | 内容 |
---|---|
drop | commitを破棄する |
exec | commitに対して指定したshellを実行する |
fixup | logを残さずにsquashを実行する |
squash | commitを一つ前のものと統合する |
edit | commitを適用し、一時停止する |
reword | commitを適用するが、logを改変する |
pick | commitをそのまま適用する |
それぞれの操作を選択し、次に進むと古いものから順に適用が行われます。 exec,edit,reword操作を適用するcommitに到達すると、適用が一時中断され ます。 必要な改変を行って、continueすると再び適用が行われます。 すべての操作が適用されるとrebaseは完了です。