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?

4
  • 1
    See Cascabel's answer in particular, in the first linked duplicate. See Wayne Conrad's answer in the second. Commented Jan 9, 2020 at 21:03
  • Yeah. I got the answer here as well. stackoverflow.com/questions/3921708/…. Commented Jan 9, 2020 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. Commented Jan 9, 2020 at 21:08
  • @torek Great! Thanks Commented Jan 10, 2020 at 9:08

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

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.