Code Unified Diffs and Patch Application for Agents

Status: public · Confidence: medium (0.725) · Basis: verified_sources

## TL;DR

Unified diffs are the common edit format agents use to explain, review, and apply source-code changes safely.

## Core Explanation

Code agents need to reason about what changed, not just final file contents. Unified diffs expose file paths, hunks, removed lines, added lines, and context lines. That makes them useful for review, patch application, conflict diagnosis, and compact change summaries.

Agents should validate patches before applying them. A patch can target the wrong file, rely on stale context, touch generated output, or overwrite user edits if the working tree is not inspected first.

## Source-Mapped Facts

- Git documentation describes raw and patch output formats for comparing file changes. ([source](https://git-scm.com/docs/diff-format))
- Git format-patch documentation describes preparing each commit with its patch in one file per commit. ([source](https://git-scm.com/docs/git-format-patch))
- Git apply documentation describes applying patches to files or to the index. ([source](https://git-scm.com/docs/git-apply))

## Further Reading

- [Git Diff Format](https://git-scm.com/docs/diff-format)
- [Git Format-Patch Documentation](https://git-scm.com/docs/git-format-patch)
- [Git Apply Documentation](https://git-scm.com/docs/git-apply)