3

I need some help with squashing commits in GitHub.

I have about 30 commits and I want to squash the first 10 commits into one single squashed commit and another 10 commits into another squashed commit. I have used git rebase -i HEAD~10 and squashed the first 10 commits. That works fine. But when I try to squash the next 10 commits, the previously squashed commit also appears in the list. Even though I didn't change the option for squashed commit from "pick" to "squash" that was also included in the resulting squashed commit. As a result I got only one squashed commit. Can anybody please guide me to get two separate squashed commits as per my requirement.

Thanks in advance

  • “I have used git rebase -i HEAD~10 and squashed the first 10 commits.” Show how you configured the pick list when you did that, what the log looked like after, and what you want to do now. – matt May 11 '20 at 20:41

1 Answers1

4

You need to use pick for the first commit in the new group; squash entries squash onto the previous commit.

And for what it's worth, you can do it in a single rebase. If your pick list looks like

pick a
squash b
squash c
pick d
squash e
pick f
squash g
squash h

You will get one commit with a+b+c squashed, one with d+e, and one with f+g+h.

hobbs
  • 223,387
  • 19
  • 210
  • 288