git absorb

Git subcommand that automatically creates fixup! commits from staged changes by finding the commit each hunk belongs to, with optional autosquash rebase.

install

git absorb is a Git subcommand, ported from Facebook's hg absorb, that takes staged changes and turns them into fixup! commits targeting the earlier commits they belong to. It removes the need to look up commit SHAs for git commit --fixup or to build an interactive rebase by hand. A typical use is applying code review feedback to a feature branch while keeping atomic commits.

The workflow is git add the files you changed, then run git absorb. Only content in the index is considered. Each resulting fixup! commit message names the target commit's message (if unique) or its SHA. With --and-rebase, the fixups are folded into their targets automatically. Otherwise you can inspect them with git log and run git rebase -i --autosquash. GIT_SEQUENCE_EDITOR can be set to skip editing the rebase TODO. If the result is wrong, git reset --soft PRE_ABSORB_HEAD restores the pre-absorb state.

To pick a target, git absorb checks whether each staged hunk commutes with each commit, starting from HEAD and going backward. The first commit that does not commute with the hunk is taken as its parent. Hunks that commute with every commit in range stay staged and a warning is shown. By default the last 10 commits are considered, and --base <ref> sets the first commit explicitly.

It is written in Rust and uses a statically linked libgit2 rather than the system one. Release binaries are provided for Windows, macOS and Linux. It is aimed at developers who maintain clean commit histories on feature branches.

Installation

# via Homebrew
brew install git-absorb
# via apt (Debian/Ubuntu)
apt install git-absorb
# via Cargo
cargo install git-absorb

Alternatives & related tools

add a badge to your README

Maintain git absorb? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/git-absorb.svg)](https://www.trmn.sh/tools/git-absorb?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/git-absorb?utm_source=badge"><img src="https://www.trmn.sh/badge/git-absorb.svg" alt="Featured on trmn" height="20"></a>