How to git rebase -i for a range of commits?

Dylan Valade picture Dylan Valade · Oct 13, 2011 · Viewed 14.5k times · Source

Can I squash a range of commits for a local feature/topic branch using rebase that does not include the most recent commit? This is for commits that I want to prepare before they get merged and pushed to a public repo.

I was working quickly and made a bunch of minor changes with poor titles and descriptions that I want to squash into two or three separate logical commits with a great comments. Can I select a range of commits between 329aed9 and af39283 that could be at any point in this feature branch's short history?

git rebase -i RANGE_START_COMMIT_ID RANGE_LAST_COMMIT_ID

Thanks!

Answer

Karl Bielefeldt picture Karl Bielefeldt · Oct 13, 2011

You could always create a new branch with git checkout -b new_branch af39283, and then rebase that. However, if you want to include the later commits at some future point, there's no getting around rebasing them as well. The SHA1 for a commit depends on all its ancestor commits.