LoginSignup
35
15

More than 5 years have passed since last update.

git rebase時にマージコミットを保持する

Last updated at Posted at 2018-05-11

単純にgit rebase branchすると、現在のツリーにあるマージコミット(Merge commits)は消失してしまいます。これを避けるためには、Preserve Mergesオプションを使います。

git rebase --preserve-merges {branch_name}

-p として省略することもできます。

git rebase -p {branch_name}

マニュアルの引用

-p
--preserve-merges

Recreate merge commits instead of flattening the history by replaying commits a merge commit introduces. Merge conflict resolutions or manual amendments to merge commits are not preserved.

This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).
マージコミットが導入したコミットを再生して履歴を平坦化するのではなく、マージコミットを再作成します。マージ競合解決またはマージコミットの手動修正は保存されません。

これは--interactive機構を内部的に使用しますが、--interactiveオプションと明示的に組み合わせることは、あなたが何をしているのか分からない限り、一般的には良い考えではありません(以下のバグを参照)。

参考

git-rebase
Stack Overflow: Git: rebase merge commit

35
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
15