1

I have a project with a messy history which gets messier the further back into the past you look. What I am trying to do is to preserve everything up to a specific commit, and squash everything from that commit onward. So in the following scheme, I would like to keep everything between and including A and B as is, and squash everything between B and C:

A-...-B-...-C

Unfortunately, when doing an interactive rebase I seem to end up flattening the entire history along the way, which is not ideal. I would like to still see the branches and merges between A and B. Is there any straightforward way to do that? Am I missing something really simple?

principal
  • 493
  • 1
  • 6
  • 15
  • 1
    [Keep merges?](http://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why) – Basilevs Nov 25 '14 at 17:00
  • possible duplicate of [Squash my last X commits together using Git](http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git) – Andrew C Nov 25 '14 at 19:23
  • The --preserve-merges option was what I was looking for precisely. Thank you! – principal Nov 26 '14 at 11:41

1 Answers1

0

You should write

$ git rebase -i HEAD~N

where N is the number of commits between B and C.

You should squash each of the other commits into C. On the branch you've rebased in, you will have all the commits between A and B preserved.

Also see this tutorial: http://pcottle.github.io/learnGitBranching/.

La-comadreja
  • 5,627
  • 11
  • 36
  • 64