git-branchless

repository·master·Indexed 26 days ago

https://github.com/arxanas/git-branchless

A suite of tools for Git providing a branchless workflow, including patch-stacking, divergent development, and high-performance operations for large-scale repositories. Key features include `git undo` for reversing complex operations, `git smartlog` (git sl) for advanced history visualization, and `git restack` for repairing commit graphs. Version 0.11.1 includes supporting libraries like git-branchless-lib and scm-bisect for identifying bad commits in a DAG.

Tokens
17.4K
Snippets
32
Records
113
Agent score
87%

What's inside git-branchless

  1. Overview of git-branchless features

    master

    git-branchless is a suite of tools designed to enhance Git workflows, specifically focusing on patch-stacking, prototyping, and high-performance operations in large repositories.

    Key Capabilities:

    • Ease of Use: Includes git undo for general-purpose undoing of commits, merges, rebases, and branch operations; git smartlog for advanced history visualization; and git restack for repairing broken commit graphs.
    • Power User Flexibility: Supports patch-stack workflows, divergent development for prototyping, git sync for rebasing all local stacks without checking them out, and git move for subtree manipulation.
    • High Performance: Optimized for monorepos and large repositories (e.g., Linux kernel) using in-memory operations, custom sparse indexes, and multithreading to avoid slow working-copy updates.
  2. Install git-branchless

    master

    You can install git-branchless using your system's package manager or via Cargo. After installation, you must initialize the tool within your Git repository.

    1. Install the package (e.g., via Cargo).
    2. Run git branchless init inside your repository to complete the setup.
  3. Undo Git operations with git undo

    master

    git undo provides a high-level abstraction for reversing repository states. Unlike git reflog, which tracks individual reference movements, git undo can handle complex operations like rebases and branch deletions.

    Supported operations:

    • Commits and amended commits.
    • Merges and rebases (including fixing wrongly resolved conflicts).
    • Checkouts.
    • Branch creations, updates, and deletions.

    Limitations:

    • Cannot currently 'uncommit' a commit to restore changes to the working copy (use git reset HEAD^ for this).
    • Cannot undo staging/unstaging of files.
    • Cannot undo into the middle of a conflict state.
    • Does not handle untracked files.
  4. Visualize history with git smartlog (git sl)

    master
    Use git sl (smartlog) to visualize your commit history. Unlike git log --graph, which only shows commits with attached branches, git sl is designed for workflows where you rewrite the commit graph extensively. It also identifies abandoned commits (descendants of commits marked as rewritten as <hash>) that need to be repaired using git restack.
  5. Apply fixes to commits using `git test fix`

    master

    The fix subcommand allows you to run a command and automatically amend the commits with any changes produced by that command. This is useful for automated bug fixing or linting.

    Key behaviors:

    • It uses the apply_fixes logic to rewrite commits.
    • It requires move_options to determine how commits are rewritten (e.g., whether to force rewrite public commits).
    • It is not compatible with the --on-disk option; use --in-memory instead.
  6. Split commits into separate commits

    master

    The split command allows you to extract changes from a single commit into separate commits. This is useful for breaking down large, monolithic commits into smaller, more manageable ones. The command can take a list of files to extract and supports different modes for how the extracted changes are integrated into the history.

    When splitting, the command also handles restacking the descendants of the target commit to maintain a clean history.

  7. Restack abandoned commits

    master

    The restack command automates the process of fixing a broken commit graph caused by rewrites (like git commit --amend). When a commit is amended or rewritten, its descendants become 'abandoned' because they are still based on the old, now-obsolete commit. restack finds these abandoned commits and rebases them onto the new, rewritten versions of their parents, restoring a continuous history.

    This command can be applied to specific commits using revsets or to all obsolete commits in the repository.

  8. Use the `undo` TUI to select a past state

    master

    When calling undo() with interactive: true, a TUI is launched. The interface provides a visual commit graph and a numbered list of events.

    TUI Commands:

    • h / ?: Show help
    • q / Q: Quit
    • n / N / Right: View next state
    • p / P / Left: View previous state
    • g / G: Go to a specific event ID (opens a dialog to enter an ID)
    • Enter: Revert the repository to the currently selected state (requires confirmation in the terminal)
  9. Commit changes with `record`

    master

    The record command allows you to commit changes from your working copy. It supports several modes of operation:

    • Standard Commit: Commits staged or unstaged changes. If changes are unstaged, it can automatically include them.
    • New Commit: Creates a brand new commit (useful for starting a new branch or recording a state without existing changes).
    • Interactive Mode: Provides an interactive interface to select specific hunks or files to include in the commit.
    • Fixup Mode: Uses --fixup <revset> to create a commit that is intended to be combined with an existing commit.
    • Stash Mode: Uses --stash to create a temporary commit of your current changes and then checks out the previous commit (effectively a stash).
    • Insert Mode: Uses --insert to move the current commit and its descendants to be siblings of the current HEAD, effectively inserting a new commit into the history.

    Key features include support for untracked files via a configurable strategy and the ability to specify a new branch name during creation.