locsquash

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 11 Imported by: 0

README

locsquash

A CLI tool to squash the last commits in your Git repository into a single commit.

Installation

go install github.com/OutOfStack/locsquash@latest

Or build from source:

git clone https://github.com/OutOfStack/locsquash.git
cd locsquash
make build                    # version = dev
make build VERSION=v1.0.0     # version = v1.0.0

Usage

locsquash -n <count> [options]
Required
  • -n <count> - Number of commits to squash (must be at least 2)
Options
  • -m <msg> - Custom commit message for the squashed commit (defaults to the oldest commit's message)
  • -stash - Auto-stash uncommitted changes before squashing
  • -allow-empty - Allow creating an empty commit if squashed changes cancel out
  • -dry-run - Preview the git commands without executing them
  • -print-recovery - Print recovery commands and exit
  • -v, -version - Print version and exit

Examples

Squash the last 3 commits:

locsquash -n 3

Squash the last 5 commits with a custom message:

locsquash -n 5 -m "feat: consolidated feature implementation"

Preview what would happen without making changes:

locsquash -n 3 --dry-run

Squash with uncommitted changes (auto-stash):

locsquash -n 3 --stash

How It Works

  1. Creates a backup branch (locsquash/backup-<timestamp>) before any changes
  2. Optionally stashes uncommitted changes if --stash is provided
  3. Performs a soft reset to HEAD~N
  4. Creates a new commit with all changes, preserving the most recent commit's date and using the oldest commit message (unless -m is provided)
  5. Restores stashed changes if applicable

Development

make build                # Build binary to bin/
make build VERSION=v1.0.0 # Build with specific version
make run                  # Run without building
make test                 # Run tests with race detector
make test-docker          # Run tests in Docker
make lint                 # Run linter

Releasing

To create a new release:

git tag v1.0.0
git push --tags

This triggers CI to build binaries for all platforms (Linux, macOS, Windows) and create a GitHub Release with that version.

Recovery

If something goes wrong, recover using the backup branch:

git reset --hard locsquash/backup-<timestamp>

To see recovery instructions before running:

locsquash -n 3 --print-recovery

Documentation

Overview

Package main provides the locsquash CLI

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL