できない.dev

Git rebase でコンフリクトが起きて先へ進めない

git rebase でコンフリクトしたら、衝突を直して git add し、git rebase --continue で次へ進む。
コミットごとに繰り返し衝突することがある。
やめるなら --abort で開始前に戻せる。

公開: 更新:

症状できない · exit 1
git rebase master
…
error: could not apply 1ee50a9... feature: edit line2
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
解決後できた · exit 0
git rebase --continue
[detached HEAD 3e437c7] feature: edit line2
 1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/feature.

2026-11-15 に alpine/git(Git 2.54.0) で実際に打って取った出力。検証環境の詳細

要約

git rebase 中に表示される CONFLICT (content): は、適用中のコミット 1 つに対する衝突である。
衝突を解消したら git add してから git rebase --continue で次のコミットに進む。
途中で諦めたい場合は git rebase --abort を打てば、rebase 開始前の状態に戻せる。

実行例

alpine/git 環境(Git 2.54.0)で上記の手順を動かすと、CONFLICT (content): Merge conflict in f.txt が発生し、rebase の終了コードは 1 になった。
マーカーの解消・git add・git rebase --continue の一連の操作で終了コード 0 になり、Successfully rebased and updated refs/heads/feature. が出力された。

$ git rebase master
Auto-merging f.txt
CONFLICT (content): Merge conflict in f.txt
error: could not apply 1ee50a9... feature: edit line2
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 1ee50a9... # feature: edit line2
$ echo $?
1
$ git status --short
UU f.txt
$ git checkout --theirs f.txt
Updated 1 path from the index
$ git add f.txt
$ git rebase --continue
[detached HEAD 3e437c7] feature: edit line2
 1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/feature.
$ echo $?
0
$ cat f.txt
line1
FEATURE
$ git log --oneline
3e437c7 feature: edit line2
bd5a883 main: edit line2
35fe47b init

— 2026-11-15 時点の出力

検証環境Git 2.54.0 / 2026-11-15 検証
検証日
実行環境
alpine/git Alpine Linux v3.24
バージョン
  • Git 2.54.0

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

解決策

1. 標準的な解消フロー

git rebase main
# CONFLICT が出たら
$EDITOR path/to/file        # マーカーを消し、正しい内容に編集
git add path/to/file
git rebase --continue

衝突が複数コミットにまたがる場合は、同じ手順を都度繰り返す。

2. 中断して元に戻す

git rebase --abort

rebase 開始直前の HEAD に戻る。
rebase 前のコミットは失われない。

3. 状態確認

git status
# rebase in progress; onto <sha>
# Unmerged paths: ...

rebase 中であること、衝突しているファイルがどれかを常に確認する。

4. 事前にコミットを整理する

衝突が多発するなら、git rebase -i HEAD~N で fixup / squash にまとめてから本番の rebase に入ると、衝突回数が減る。

よくある原因

  1. コミット単位で何度もぶつかる。
    rebase は対象コミットを 1 個ずつ再適用するため、同じファイルで衝突が連発することがある。
  2. コンフリクトマーカーを残したまま add した。
    <<<<<<< ======= >>>>>>> を消し忘れたまま git add すると、壊れた内容がコミットされる。
  3. continue を忘れて commit した。
    通常どおり git commit してしまうと、rebase の進行管理が壊れる。
  4. abort を知らない。
    行き詰まって、新しいクローンを作り直してしまう。