2012年2月4日土曜日

gitで過去を改ざんする(5/5)


ではgit rebaseでガッと行きます。
変更を施す一つ前のリビジョンを指定。
$ git rebase -i 40e910ba
こんなのがエディタで開きます。
pick f1cf7c1 途中まで(早春賦)
pick a5bdfe7 誤字を修正
pick b3d4dfa 歌詞を最後まで(早春賦)
pick 20899eb 途中まで(椰子の実)
pick fe623a8 レイアウトを修正
pick 85767e2 歌詞を最後まで(椰子の実)
pick 94fba12 作詞者を追加(早春賦)
pick 16d9acd 作詞者を追加(椰子の実)

# Rebase 40e910b..16d9acd onto 40e910b
#
# 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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
こんなふうに変更して保存します。
edit f1cf7c1 途中まで(早春賦)
fixup a5bdfe7 誤字を修正
edit b3d4dfa 歌詞を最後まで(早春賦)
edit 20899eb 途中まで(椰子の実)
fixup fe623a8 レイアウトを修正
edit 85767e2 歌詞を最後まで(椰子の実)
edit 94fba12 作詞者を追加(早春賦)
fixup 16d9acd 作詞者を追加(椰子の実)
(以下略)
詳細はコメントになっている部分を読んでください。
fixupとしているものは、その上の行に混ぜ込まれます。
editは、コミットログを書き換えるためです。

保存するとこんなメッセージが出てきます。
Stopped at f1cf7c1... 途中まで(早春賦)
You can amend the commit now, with

 git commit --amend

Once you are satisfied with your changes, run

 git rebase --continue

--amendでコミットログを書き換えます。
$ git commit --amend -m "早春賦を途中まで"
[detached HEAD 79526ef] 早春賦を途中まで
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 sousyunfu.txt
$
一旦終わったように見えますが、まだrebaseの途中です。
$ git rebase --continue
[detached HEAD 63992fe] 早春賦を途中まで
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 sousyunfu.txt
Stopped at b3d4dfa... 歌詞を最後まで(早春賦)
You can amend the commit now, with

 git commit --amend

Once you are satisfied with your changes, run

 git rebase --continue
同様にやっていきます。
$ git commit --amend -m "早春賦を最後まで"
$ git rebase --continue
$ git commit --amend -m "椰子の実を途中まで"
$ git rebase --continue
$ git commit --amend -m "椰子の実を最後まで"
$ git rebase --continue
$ git commit --amend -m "作詞者を追加"
$ git rebase --continue
一番最後にこう出ます。
Successfully rebased and updated refs/heads/work_3.
$



Eclipseで見てみると…
出来上がりです!
ORIG_HEADの枝はこの後mergeか何かすれば動いて消えるので、気にしなくてもOKです。



おっと、ブランチ名がwork_3では格好がつかない。
$ git branch -m work_3 master



完了。

0 件のコメント:

コメントを投稿