S-JIS[2018-01-13] 変更履歴
Gitのrebaseコマンドのメモ。
過去のコミットを修正する(履歴を変更する)のがrebaseコマンド。
他の人と共有するリポジトリーを使っている場合は、rebaseコマンドは使わない方が良い。
rebaseすると履歴が変わるが、履歴が変わると共有リポジトリーに対してpushしたりpullしたりしたときにエラーになるから。
ある修正Aをコミットをし、さらに別の修正Bをコミットした後で、Aの修正漏れに気付き、Aに修正を追加したい。
$ git add .
$ git commit -m'temp' ←適当なメッセージでコミット
$ git log
commit 221d131cd6b4d3233670f8adbb5ff7932be4dad8 (HEAD -> master)
Author: hishidama
Date: Sat Jan 13 11:37:26 2018 +0900
temp
commit 001bc6cdeeeff26ecf2404b995d0c28ce71a2a0e
Author: hishidama
Date: Sat Jan 13 11:36:54 2018 +0900
bbb
commit 357d521b0249d1f3abe5ea4dc94acb427d5e2b14 ←これ
Author: hishidama
Date: Sat Jan 13 11:36:26 2018 +0900
aaa
$ git rebase -i 357d521b0249d1f3abe5ea4dc94acb427d5e2b14^すると、エディターで以下のようなメッセージが表示される。
pick 357d521 aaa pick 001bc6c bbb pick 221d131 temp # Rebase e6c75c8..221d131 onto e6c75c8 (3 commands) # # 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 〜
pick 357d521 aaa s 221d131 temp pick 001bc6c bbb
# This is a combination of 2 commits. # This is the 1st commit message: aaa # This is the commit message #2: temp
# This is a combination of 2 commits. # This is the 1st commit message: aaa