4

While rebasing with master, the merge commits are gone missing whereas the code change remains intact.

Initial branch (not master) state before rebasing :

commit 52c********************************
Merge: 1******
Author: M*********************************
Date:   Tue Feb 9 17:49:25 2016 +0530

    Merge pull request #1342 from *********************

    Changes for ******************

commit 6be**********************************
Author: Ma***********************************
Date:   Tue Feb 9 14:39:48 2016 +0530

    Changes for W********************************
    commit ef2***********************************

Once we rebase with master, the merge commit that starts with "52c.." is missing in the git log.

Amal
  • 181
  • 5
  • 3
    Would a `git rebase -p` (`--preserve-merges`) work better in your case? – VonC Feb 10 '16 at 06:16
  • Do you rebased an already pushed branch? Rebasing is changing the history in certain cases. Thats why you maybe don't find the merge commit. – ckruczek Feb 10 '16 at 06:29
  • 1
    thanks, "git rebase -p" did the job for me. – Amal Feb 11 '16 at 04:09
  • Does this answer your question? [What exactly does git's "rebase --preserve-merges" do (and why?)](https://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why) – Guildenstern May 06 '23 at 12:27

1 Answers1

0

The git rebase --rebase-merges, that I presented here with Git 2.18 (Q2 2018) replaces the old --preserve-merges I mentioned in the comments back in 2016.

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.

So while git rebase -p worked in 2016, the current answer is git rebase -r.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250