かもメモ

自分の落ちた落とし穴に何度も落ちる人のメモ帳

Git merge commit を残して rebase したい

GitHub 使ってるとブラウザ上の PR と整合性が取れなくなるからそんなに使うことはないかもだけど、個人のプロジェクトで過去改変したいときに

--rebase-merges (-r) オプションを使う

$ git rebase -i --rebase-merges <commit hash>

--rebase-merges[=(rebase-cousins|no-rebase-cousins)]
By default, a rebase will simply drop merge commits from the todo list, and put the rebased commits into a single, linear branch. With --rebase-merges, the rebase will instead try to preserve the branching structure within the commits that are to be rebased, by recreating the merge commits. Any resolved merge conflicts or manual amendments in these merge commits will have to be resolved/re-applied manually.
cf. Git - git-rebase Documentation

📝 -s (--preserve-merges) は廃止

-p --preserve-merges
[DEPRECATED: use --rebase-merges instead]
cf. Git - git-rebase Documentation

おわり


[参考]