Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/akirak/squasher

Squash consecutive Git commits
https://github.com/akirak/squasher

auto-commit git

Last synced: 5 days ago
JSON representation

Squash consecutive Git commits

Awesome Lists containing this project

README

        

* Squasher for Auto-Committed Git Repositories
[[https://akirak.cachix.org][https://img.shields.io/badge/cachix-akirak-blue.svg]]

This is a command line program that addresses a very particular need: squash Git commits that are automatically created (e.g. using [[https://github.com/ryuslash/git-auto-commit-mode][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.
** Installation
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:

#+begin_src sh
nix run github:akirak/squasher -- --help
#+end_src
** Usage
Synopsis:

#+begin_src sh
squasher [--base SHA] [--hours N] [DIR]
#+end_src

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.