git am: patch format corruption
Quick summary
You ran git am with a patch file that has corrupted or malformed mbox format — git cannot parse the commit metadata or diff content.
Why this happens
The patch file was truncated during download or email transfer, cutting off part of the diff content
The mbox format has invalid headers or missing separator lines between multiple patches in a series
Line endings were converted from LF to CRLF (or vice versa) during transfer, corrupting the diff context lines
Minimal example
git am patch.mbox # error: patch format defect: truncated diff
# or: Patch is emptydos2unix patch.mbox # fix line endings
git am --abort # clean up partial state
git am patch.mbox # retry with fixed fileFixing line endings and aborting the partial application state lets git re-parse the patch from a clean starting point, resolving the format corruption.
How to diagnose
Inspect the patch file with cat or less to check for truncation, missing headers, or garbled content
Run file patch.mbox to check encoding and line endings — patches must use LF line endings
Use git am --abort to clean up the partially applied state, then re-examine the patch source
How to fix
Re-download or re-export the patch from the original source to get a complete, uncorrupted file
Fix line endings with dos2unix patch.mbox or sed -i 's/\r$//' patch.mbox before applying
Split a multi-patch mbox into individual files and apply them one at a time with git am to isolate the corrupted entry
How to prevent
Use git format-patch to generate patches in a clean mbox format and transfer them as binary to avoid line ending corruption
Verify patch integrity with git apply --check before committing with git am to catch format issues early