git、コミット漏れのファイルがあった時の対処

ストーリーとしては、

$ vi main.rb
  ...
$ vi newclass.rb
  ...
$ git commit -a -m '一部機能をNewClassに分離'

$ vi main.rb
$ git commit

$ vi sub.rb
$ git commit

  ...
$ git status
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       newclass.rb
$ うっ
bash: うっ: command not found

みたいなケースですね。

bash: うっ: command not found

# 「本来そのファイルを入れるはずだったコミット」の手前までを指定してrebase -i
$ git rebase -i HEAD~~~~~

# そうするとエディタが開くので、当該コミットのところを"e"(edit)にする
pick 12345 あれした
e    12346 一部機能をNewClassに分離
pick 12347 なんかした
pick 12348 きのうついか
pick 12349 ばぐしゅうせい

# エディタを保存終了すると、当該コミットでストップするので、

# 漏れてたファイルを追加、

$ git status
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       newclass.rb

$ git add newclass.rb

# 当該コミットに上書きする
$ git commit --amend

# あとはcontinueしておわり
$ git rebase --continue