Git: Interactively rebase a range of commits
Just use rebase -i
and squash only those commits.
git rebase -i <main_branch>
# Now just add `s` in front of all the commits you want to squash
If you have many commits, I'd suggest you to take a look at rebase --onto
-
git rebase --onto <final_base_commit> <initial_base_commit> <head>
git rebase --onto 694bdda 64bd9e7 5e32fb0
Note: Rewriting history is an advanced operation, so tread with care.
Git rebase tutorial
You say "git rebase -i HEAD~106
isn't very practical".
If you mean that the resultant script file is >100 lines long, it's not great, but it'll work.
If you mean that it's tedious to count back, to work out that you need the 106 commits - as sometimes happens to me, then there is a solution.
You need the hash of the parent of the earliest commit you want, then you can do:
git rebase -i <parent-hash> my-branch
Or you can do
git rebase -i <parent-hash> HEAD
which afterwards will leave you on a detached head that you can do what you want with.
So in your example, you could have done
git rebase -i 694bdda HEAD
(But I would still agree with the other comments, about whether you really want to be changing things that far back. I think it's a bit of a code smell, when I find myself doing it. It's unusual for me to have such a long branch without pushing/sharing it. I'd make a backup branch to test it on, too.)