LinuxCommandLibrary

git-rebase-patch

Apply patch series from mailbox format

TLDR

Find the commit the patch applies to and do a rebase

$ git rebase-patch [patch_file]
copy

SYNOPSIS

git rebase --apply [options...] [<upstream> [<branch>]]

PARAMETERS

--apply
    Apply commits as patches linearly (no merge commits)

--merge
    Default: use merge strategy (negated by --apply)

-i, --interactive
    Interactive rebase mode

--onto <newbase>
    Rebase onto specific new base commit

--continue
    Resume rebase after resolving conflicts

--abort
    Abort rebase and reset to original branch

--quit
    Abort without resetting branch state

--skip
    Skip current commit and continue

-p, --rebase-merges
    Preserve original branch structure (requires --interactive)

--keep-empty
    Keep empty commits

-x <cmd>, --exec <cmd>
    Run command after each commit

-r, --rebase-merges=interactive
    Interactive forward rebase of merges

--autosquash
    Automatially squash fixup commits

-v, --verbose
    Verbose output

-q, --quiet
    Quiet operation

--autostash
    Automatically stash/stash-pop uncommitted changes

--no-autostash
    Do not automatically stash changes

--verify-signatures
    Verify GPG signatures

--no-verify
    Skip verification of pre-commit hooks

<upstream>
    Base commit/branch to rebase onto

<branch>
    Working branch; current if omitted

DESCRIPTION

git-rebase-patch is not a standard standalone Git command but refers to the patch application mode of git rebase --apply. This mode rebases commits by generating patches for each commit on the working branch and applying them sequentially onto a new base using git am internally.

This approach produces a linear history without merge commits, making it ideal for simplifying commit sequences before pushing or merging. It is faster than the default --merge strategy for linear histories but less robust for handling conflicts or preserving merge structures.

During rebase, if conflicts arise, Git pauses, allowing manual resolution before continuing with git rebase --continue, aborting with --abort, or skipping with --skip. Best for topic branches with linear changes; avoid on shared branches to prevent rewriting public history.

Equivalent to git format-patch followed by git am, but automated within rebase.

CAVEATS

--apply fails on merge commits, complex conflicts, or binary files; use --merge or -i instead. Rewrites history—never rebase public/shared branches. No rename detection.

BASIC EXAMPLE

git rebase --apply origin/main
Rebase current branch linearly onto origin/main.

git rebase --apply --onto develop feature
Rebase feature onto develop.

CONFLICT RESOLUTION

Edit files, git add resolved hunks, then git rebase --continue.
Use git rebase --abort to cancel.

INTERNAL MECHANISM

Generates patches via git format-patch --stdout | git am --3way.

HISTORY

Git rebase introduced in 2005 (Git 0.99.9h) by Junio C Hamano. --apply added early for patch-mode efficiency. Evolved with --interactive (2006), --preserve-merges, and modern rebase-merges (Git 2.18+). Patch mode remains for linear, fast rebases.

SEE ALSO

Copied to clipboard