最初に結論
git rebase --skip すれば良い。

状況
git rebase や git merge で、 conflict することがあります。この時、大抵はコンフリクトを解消し、git add して git rebase --continue や git merge --continue すれば解決します。
しかし、コンフリクトを解消した結果、git add するものがなくなってしまった場合、git rebase --continue すると以下のエラーメッセージが出ます。
$ git rebase --continue Applying: ほげほげを修正 No changes - did you forget to use 'git add'? If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this patch.
実際に起こった例
ブランチAをmasterにrebaseしようとしてコンフリクトします。
$ git checkout A $ git rebase master First, rewinding head to replay your work on top of it... Applying: ほげほげを修正 Using index info to reconstruct a base tree... M hogehoge.php Falling back to patching base and 3-way merge... Auto-merging hogehoge.php CONFLICT (content): Merge conflict in hogehoge.php Failed to merge in the changes. Patch failed at 0001 ほげほげを修正 The copy of the patch that failed is found in: /home/yoshiyuki_sakamoto/.git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".
ここで実は If you prefer to skip this patch, run "git rebase --skip" instead. って出てたんでね...(気づかなかった)
- コンフリクトを解消して続ける場合は
git rebase --continue - このパッチを飛ばす場合は
git rebase --skip - rebaseを諦める場合は
git rebase --abort
としろと。
解決する
まあとりあえずコンフリクトを解消しようとします。 git status や git diff を見てみます。
$ git status
rebase in progress; onto f8464df
You are currently rebasing branch 'batch-pdo' on 'f8464df'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: hogehoge.php
$ git diff
diff --cc hogehoge.php
index 5e0d708,bd484f9..0000000
--- a/hogehoge.php
+++ b/hogehoge.php
@@@ -67,19 -67,11 +67,27 @@@ class Hogehoge
public function get_hoge() {
++<<<<<<< HEAD
+ $host_info = explode(':', $host_port);
+ $host = $host_info[0];
+ $port = isset($host_info[1]) ? $host_info[1] : null;
+
+ return 'mysql:host=' . $host . ';dbname=' . $this->get_db_name();
++=======
+ return 'mysql:host=' . $host_port . ';dbname=' . $this->get_db_name();
++>>>>>>> ほげほげを修正
まあ修正内容はなんでもいいのです。ここで、HEAD(つまりmasterの方)が正しそうなので、git checout HEAD hogehoge.php (git checkout master hogehoge.php とかでもいい) します。すると、
$ git checkout HEAD hogehoge.php $ git status On branch deploy nothing to commit, working tree clean
nothing to commit に、この状態で git rebase --continue しようとすると、No changes - did you forget to use 'git add'? と言われます。((continue でいいじゃないか!って思うんですけどね...)) 無をcommitすることは出来ないので git rebase --skip することになります。
continueした時に差分が無い場合は勝手にskipして欲しいと思ったりもするんですが、誤解を避けるためか勝手にskipとかはされないようになっております。
--continue, --skip, --abort ちゃんと使いこなせるようになっておきたいですね。