Skip to main content

git-surgeon

A Git subcommand for change-centric workflows, borrowing ideas from Jujutsu’s change‑centric UX while staying within Git’s history model.

Install

For development, install the project in editable mode:

pip install -e .

Or copy the wrapper script onto your PATH:

chmod +x git-surgeon
cp git-surgeon ~/bin/

Then you can call it as a Git subcommand:

git surgeon --help

Usage

git surgeon <command> [options]

Run git surgeon <command> --help for command-specific help.

Commands

Diff a commit

git surgeon diff <commit> --head -- path/to/file

Compare a commit to its parent or to HEAD.

Show a file at a commit

git surgeon show <commit> path/to/file

Prints the file contents as they existed in the commit.

Show reflog entries

git surgeon op log --count 20

Displays the recent reflog operations.

Restore a reflog entry

git surgeon op restore HEAD@{1}

Resets the repo to a specific reflog entry.

Abandon a rebase

git surgeon op abandon

Resets the repo to the commit before the last rebase.

Revert a commit via operation history

git surgeon op revert HEAD

Creates a new commit that reverts the specified commit.

Save WIP without stashing

git surgeon stashless --message "WIP: refactor" --keep-branch

Creates a WIP commit on a temporary branch.

Create a new empty commit

git surgeon new -m "WIP"

Creates an empty commit without staging changes.

Undo last git operation

git surgeon undo --hard --steps 1

Resets HEAD to a previous reflog entry.

Go to the commit before a rebase

git surgeon pre-rebase --hard

Resets to the commit before the last rebase.

Resolve the current operation

git surgeon resolve --continue

Continues, aborts, or skips the active rebase/merge/cherry-pick.

Reword a commit

git surgeon reword <commit> "New message"

Quickly amend the commit message with a new one.

Describe a commit message

git surgeon describe <commit> -m "Updated message"

reword requires a new message and amends immediately, while describe can open the editor and keep the original dates.

Edit a commit

git surgeon edit <commit>

Stops an interactive rebase at the commit, keeps the original dates, and prompts you to amend. Add --message to update the message immediately.

Set commit dates

git surgeon metaedit date <commit> "2024-01-01T12:00:00Z"

Sets committer date by default (RFC2822 or RFC3339). Use -a for author dates or -ca to set both.

Set commit author

git surgeon metaedit author <commit> "New Author"

Updates the author name without changing content.

Set commit author email

git surgeon metaedit mail <commit> "new@example.com"

Updates the author email without changing content.

Absorb staged changes

git surgeon absorb

Creates a fixup commit and autosquashes into the latest touching commit.

Squash a commit into its parent

git surgeon squash <commit>

Squashes the commit into its parent with interactive rebase.

git surgeon squash <commit> --into <target>

Squashes the commit into a specific ancestor.

Fixup a commit into its parent

git surgeon fixup <commit>

Fixups the commit into its parent, discarding its message.

Drop a commit

git surgeon drop <commit>

Drops the commit via interactive rebase.

Merge a commit or branch

git surgeon merge <commit>

Merges another commit or branch into the current branch.

Split a commit into two

git surgeon split <commit>

The tool resets the commit, then asks you to stage and create two new commits. Use --first-message and --second-message to set messages automatically.

Split a commit interactively

git surgeon split -i <commit>

Uses git add -p for the first split commit.

Swap two commits

git surgeon swap <commit-a> <commit-b>

Swaps two commits in a linear history.

Move a commit after another

git surgeon move <commit> <destination> --before

Moves a commit before or after another in linear history.

git surgeon move <commit> <destination> --onto

Moves a commit and its descendants onto the destination.

Untrack a file (keep it on disk)

git surgeon file untrack path/to/file

Removes the file from the current commit while keeping it on disk. Use --from <commit> or --root to rewrite history.

Track a file

git surgeon file track path/to/file

Starts tracking the file in the current commit. Use --from <commit> or --root to rewrite history.

Notes

  • edit, reword, and split preserve original author/committer dates.
  • squash and fixup use the default interactive rebase behavior for messages.
  • swap expects the commits to be on the same ancestry path.
  • move expects the commits to be on the same ancestry path.
  • file track and file untrack only rewrite history when --from or --root is provided.
  • metaedit date supports -a/-c with the special values author/commit to swap dates.
  • pre-rebase uses ORIG_HEAD or the reflog entry for rebase start.
  • op restore --pre-rebase or op restore pre-rebase use the same target.
  • op revert --pre-rebase or op revert pre-rebase revert that target.
  • If a rebase is already in progress, the tool will exit with an error.
  • Most commands that take a commit accept -r/--commit as an alias for the commit argument.
  • describe also accepts desc, and split -i enables interactive staging.
  • Short aliases include op log -n, undo -n, stashless -b/-k, metaedit date -a/-c, squash -f/--from -t/--to, diff -f/--from -t/--to, and move -A/-B -f/--from -t/--to.
  • Command aliases include reword r, edit e, squash s, fixup f, drop d, and merge m.

Comparisons

Tool Focus Link
git-surgeon History helpers for commit rewriting/modifying README.md
git-extras Many Git helper commands https://github.com/tj/git-extras
git-town Branch workflow automation and syncing https://www.git-town.com
jujutsu (jj) Change-centric VCS with powerful history editing https://github.com/jj-vcs/jj

git surgeon is a namespaced subcommand (git surgeon ...), so its subcommands do not collide with standalone git-* commands from other tools.

Compared to jj, git surgeon stays inside Git’s history model and wraps interactive rebase, reflog, and merge flows. jj provides a change-centric DAG with richer undo/redo semantics and native operations for moving, splitting, and absorbing changes without the same history‑rewrite steps.

AI-assistance disclaimer

Portions of this project were created or refined with assistance from AI tools (spec. Codex). AI contributions were used for code generation, refactoring, architectural exploration, naming convention review, and documentation improvement, as well as for providing guidance on compiler issues.

All AI-generated or AI-assisted content has been reviewed, validated, and approved by me; the human developer responsible for this project, and someone I am reasonably confident is, in fact, human.

Metadata

Release files for git-surgeon 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-surgeon 0.1.0
File Size Uploaded
git_surgeon-0.1.0.tar.gz 21.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for git-surgeon 0.1.0
File Interpreter ABI Platform
git_surgeon-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.8 kB

Release files / git_surgeon-0.1.0.tar.gz

Download URL git_surgeon-0.1.0.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a4a9ed3b9d9f802962541a7e6ec78633bec9b5a61450e78f1ef16edee5887c2a
BLAKE2b-256 checksum
How to use checksums
ed2157e4a3dcd062e9350de979dd7a1c5a6af00b71bc2a9a3d4fd510921d6c58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / git_surgeon-0.1.0-py3-none-any.whl

Download URL git_surgeon-0.1.0-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8dd95a40408586cdb07a0acbdfab8245fa9ef50ba2915c5ad1e3a44bc72ac45
BLAKE2b-256 checksum
How to use checksums
0ded7849d8c861ddd894c88e051e2b8a91c2a7282bb68b3bb63ee6191b4a4b73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page