0

I know that using git rebase -i, I could squash a commit which will meld the commit message into the immediate previous commit.

https://github.com/wprig/wprig/wiki/How-to-squash-commits

But using git rebase -i, is it possible to squash a commit into not the previous commit but a commit even older? Lets say I want to squash a commit with a commit that is 3 commits prior to the commit being squashed. If yes, then how?

AdeleGoldberg
  • 1,289
  • 3
  • 12
  • 28
  • 1
    See [Cascabel's answer](https://stackoverflow.com/a/2740812/1256452) in particular, in the first linked duplicate. See [Wayne Conrad's answer](https://stackoverflow.com/a/2080543/1256452) in the second. – torek Jan 09 '20 at 21:03
  • Yeah. I got the answer here as well. https://stackoverflow.com/questions/3921708/how-do-i-squash-two-non-consecutive-commits. – AdeleGoldberg Jan 09 '20 at 21:06
  • 1
    Ah, thanks, I've added that to the collection. Your question has both keywords "squash" and "rebase", which a lot of these don't. – torek Jan 09 '20 at 21:08
  • @torek Great! Thanks – AdeleGoldberg Jan 10 '20 at 09:08

1 Answers1

2

when you use git rebase -i you are able to reorder the commit if you want to a new order.

If you e.g. do git rebase -i HEAD~5 and end with this:

  pick bfddbf6 first  commit
  pick 74b19b1 second commit
  pick 03892e7 third  commit
> pick 0fdc12c fourth commit
  pick 9e422a0 fifth  commit

you can reorder the fifth commit as second to squash it into the first:

  pick bfddbf6 first  commit
> squash 0fdc12c fourth commit
  pick 74b19b1 second commit
  pick 03892e7 third  commit
  pick 9e422a0 fifth  commit
fluktuid
  • 155
  • 8