This is a command line program that addresses a very particular need: squash Git commits that are automatically created (e.g. using git-auto-commit-mode for Emacs). It squashes a consecutive sequence of commits that have the same commit message into one commit. It also checks the author time of each commit, so if a commit is not authored within a certain duration (e.g. three hours) since the first commit of the sequence, it is not squashed, even if it has the same commit message.
Squashing is applied to commits between the head and its remote branch (i.e. origin/BRANCH
unless the branch has a specific remote).
This is useful for keeping the history less messy, while frequently backing up changes to the Git repository.
It is a Go program, so you can build and install the program using Go.
Alternatively, you can use Nix with flakes enabled to run the program:
nix run github:akirak/squasher -- --help
Synopsis:
squasher [--base SHA] [--hours N] [DIR]
It takes an optional positional argument, which should be a path to a Git repository. By default, it is the current repository.
If --base
is set, squashing starts from the commit instead of origin/BRANCH
. You must give a full hash of a commit.
--hours
option specifies the duration threshold in hours.
It rewrites the history of the head branch of a Git repository, so please use it with caution. As a safety net, it checks the status of the repository and aborts the operation if it is not clean.
To automate squashing, you can create a pre-push
hook or your Git repository.