9

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?

1
  • 6
    That is the default behaviour of git-rebase. See the --preserve-merges flag in the git-rebase man page. Regarding your second question, it all depends on the shape of your commit graph; remember that ~ follows the first parent of a commit. If you edit your question and add the output of git log --graph --oneline --decorate, people here would be able to explain the situation better. Commented Mar 29, 2015 at 13:29

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Warning from the documentation: "[--preserve-merges] 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)."
2

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

git rebase -i HEAD~4 --rebase-merges 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.