Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase doesn't show merge commits

Tags:

git

git-rebase

When I do git rebase -i HEAD~4 I get something like this:

pick 7e2dd90 refactor some function
pick dad8a9e fix another bug
pick 4ba8c24 add another feature
pick aca4ba3 do other stuff
pick dd0b3e6 add feature
pick 8dad92f fix bug
pick 8571d0c stuff
pick 25b328c whatever
pick 1803bca demo commit
pick 9723acc hello, world
pick 3ff4212 blahblah
pick c5c3bcf missed a file in merge

When I do git log I get this:

commit c5c3bcf0ac65d1423ddc2785b2f9ac3ecbd930d9
Author: neubert
Date:   Sat Mar 28 22:11:08 2015 -0500

    missed a file in merge

commit 198bb3c61f62de47706fdfa3171bb79b4a0496a1
Merge: cae37ae bb01002
Author: neubert
Date:   Sat Mar 28 21:54:51 2015 -0500

    Merge branch 'branchname' into anotherbranch

    Conflicts:
        path/to/filename.ext

commit bb01002233f1eff5d42b6964e33830633f710ee1
Merge: c8fe3c3 3ff4212
Author: neubert
Date:   Sat Mar 28 21:03:17 2015 -0500

    Merge remote-tracking branch 'athirdbranchname'

commit 3ff4212b9291f2c863a742f5692ca7312b81decb
Author: neubert
Date:   Tue Mar 24 13:40:42 2015 +0800

    blahblah

commit 9723acc8853c5fe7ea9bda4a9a711a3e07575c84
Author: neubert
Date:   Tue Mar 24 13:38:56 2015 +0800

    hello, world

My question is... why isn't git rebase showing merge commits? Is that just not something it does? I'd like to squash the "missed file in merge" commit to the merge commit but if I can't see it with rebase I can't do that..

Also, shouldn't git rebase -i HEAD~4 give me four commits - not 12?

like image 675
neubert Avatar asked Mar 29 '15 13:03

neubert


People also ask

Why merge commit is not showing in rebase?

FYI, rebase doesn't normally preserve merge commits, you need to pass the -p or --preserve-merges flag for that...but there's probably an easier way to do what you want to do.

Does git rebase include merge commits?

With this option, the rebase command successfully includes all merge commits. Following screenshot shows the interactive rebase screen with --rebase-merges option: The rebase operation itself combines resets, labels, merges to preserve the same structure.

How do I rebase without merge commit?

You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". In fact, Git will list out every file that has a merge conflict in it with the CONFLICT flag!


2 Answers

try running git rebase -i HEAD~4 --preserve-merges. That will let you see merge commits and should also limit the number of commits to four.

like image 98
bjubes Avatar answered Oct 10 '22 07:10

bjubes


For git v2.22+ use --rebase-merges

git rebase -i HEAD~4 --rebase-merges
like image 23
Miguel Mota Avatar answered Oct 10 '22 08:10

Miguel Mota