Arezgitfield notes / engineering
Git workflowsUPDATED NOV 23, 2026

Review Patch Series Before Applying Them with Git Am

Export a bounded Git patch series, inspect it on a review branch, and verify that a conflicting mailbox import can stop and recover its original state.

Arezgit Editorial4 min read
AREZGIT / FIELD NOTEGIT WORKFLOWS
A patch file can apply cleanly and still implement the wrong change. Treat a mailbox series as an incoming proposal: establish its base, inspect the proposed commits, apply it on an isolated
READ / VERIFY / APPLYTECHNICALLY REVIEWED

A patch file can apply cleanly and still implement the wrong change. Treat a mailbox series as an incoming proposal: establish its base, inspect the proposed commits, apply it on an isolated branch, and test the resulting tree before integration. Preserve a clear abort path when application stops.

This local PowerShell exercise uses Git 2.45 or later and a single synthetic patch. It demonstrates both a successful import and a conflict that restores its pre-import state after abort. It does not send email or authenticate the patch author's identity.

Understand what a mailbox series preserves

The format-patch reference describes an export suitable for review and application as a series of patches. The am reference describes constructing commits from mailbox messages, including author information and commit messages. This workflow is appropriate for a bounded linear series; it is not a general way to preserve an arbitrary merge topology.

An imported commit has its own commit identity. Matching author metadata or a familiar subject line does not prove who sent the file. Establish authenticity through the project's communication and verification process. Inspect the file as untrusted input and avoid executing instructions included in its prose merely because the patch looks familiar.

Keep transport separate from acceptance. A review branch makes it possible to inspect a result without advancing the branch used by other developers. It also preserves a concrete comparison point when a maintainer edits the proposal during review.

Export one change with an explicit base

Start PowerShell in a new empty parent directory. Create a base commit and a topic branch:

git init -b main patch-demo
Set-Location patch-demo
git config user.name "Example Author"
git config user.email "author@example.com"
Set-Content -LiteralPath label.txt -Encoding ascii -Value 'draft'
git add -- label.txt
git commit -m "Create base label"
git tag base
git switch -c topic
Set-Content -LiteralPath label.txt -Encoding ascii -Value 'reviewed'
git add -- label.txt
git commit -m "Revise label"
git format-patch --base=base -1 --output-directory ../patch-mail
git log --oneline base..topic

This export creates one numbered mailbox file. The base metadata helps identify the history against which the proposal was prepared. It does not install that history in another repository or guarantee the destination is at the base.

Review the proposed range before transferring it. Check the file list, sensitive material, generated output, and whether each commit can be evaluated independently. A series with an unrelated cleanup or a hidden prerequisite is harder to apply and test reliably. For a larger series, retain the exported filenames and their order rather than guessing order from an arbitrary filesystem listing.

Inspect the result on a dedicated branch

Apply the known mailbox file on a branch starting from the base:

git switch -c review base
git status --short
git am --keep-cr ../patch-mail/0001-Revise-label.patch
git log --oneline base..HEAD
git diff base HEAD -- label.txt
git status --short

The result should contain the proposed label change and leave a clean working tree. In a real project, require a clean starting state before import. Unrelated edits make conflict recovery and attribution harder, even when Git refuses some unsafe combinations itself.

The explicit keep-CR option preserves carriage returns in the mailbox. This matters when the synthetic text files were committed with CRLF content rather than normalized to LF. Confirm the repository's line-ending policy before adapting the example; changing transport normalization can make otherwise identical-looking patch context fail.

Inspect the resulting tree and run the relevant tests. Patch application checks whether edits can be applied, not whether authorization still holds, resources are released, or a new behavior matches the requirement. Compare the review result with the intended base and document any adaptation needed for the current branch.

Do not silently discard a patch because its subject appears elsewhere in history. Equivalent changes can have different commit identities, and similar subjects can describe different edits. Investigate the actual content before deciding whether the proposal is already present.

Stop at a conflict and recover the original state

Create a conflicting receiver branch from the original base. Preserve its identity before import:

git switch -c conflict base
Set-Content -LiteralPath label.txt -Encoding ascii -Value 'approved'
git add -- label.txt
git commit -m "Choose a different label"
$beforeImport = git rev-parse HEAD
git am --keep-cr ../patch-mail/0001-Revise-label.patch

The final command should fail because the receiver changed the same line. This is the exercise's denial path, so stop and inspect the operation rather than running a generic commit command. Display the current proposal and choose the bounded recovery:

git status --short
git am --show-current-patch=diff
git am --abort
git rev-parse HEAD
git status --short
Get-Content -LiteralPath label.txt

After abort, HEAD should equal the saved value, status should be clean, and the label should remain approved. Those observations distinguish successful recovery from merely ending the mailbox operation. If resolving instead, inspect the conflict, stage the deliberate result, and continue through the operation's documented continuation command.

Do not use skip to conceal an unexplained failure: it drops the current proposal from the imported series. If adaptation changes behavior, describe that change for the proposer and rerun the tests. When finished, leave the exercise directory before removing its synthetic files. A real acceptance record should identify the reviewed base, imported series, resulting commit, and behavioral checks that justified integration.

READER SIGNAL

Was this guide useful?

Your rating helps us prioritize clearer, more practical technical content.

AREZGIT / DESKTOP WORKSPACEFROM FIELD NOTE TO RELEASE

Review diffs, run checks, and prepare the release in Arezgit.

Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.

Explore Arezgit