I have a tendency of creating many small commits when working on a new feature.
While this may have some advantages, like ease of review, clear context and quick fallbacks, I find myself in need of squashing these commits before the actual merge.
In order to use git’s interactive rebase to rearrange my commits, I need to find out the number of relevant commits.
Sure, I can use tig or
git log --pretty=oneline and simply count them, but where’s the fun in that?
Today I learned how to count commits between different branches AWA within a branch.
# of commits between master and the current branch:
$ git rev-list --count master..HEAD
You can replace the
HEADparameters with any branch name or commit SHA
The command uses
rev-listflag which lists commit objects in reverse chronological order, then counts them from the starting index to the final one.
$ git rebase -i HEAD~<number-of-commits>