Diff Prefix Repair
GitAuto ensures that unified diff files have proper a/ and b/ prefixes in their --- and +++ lines. The model often omits these prefixes, which causes git apply to reject the entire patch.
Why This Exists
The unified diff format requires file paths in header lines to be prefixed with a/ for the original and b/ for the modified version. The model frequently generates diffs like --- src/index.ts instead of the correct --- a/src/index.ts. Without these prefixes, git apply rejects the patch outright. This was a persistent failure that wasted agent iterations because the error message from git was not always clear about the cause.
Why Models Forget Diff Prefixes
The a/ and b/ prefixes are a git-specific convention that carries no semantic meaning - the file path is the same with or without them. Models have seen diffs with and without prefixes in training data (many online examples omit them), so the model has no strong signal that they are required. Since omitting them does not change the meaning of the diff, the model frequently drops them. Only strict format parsers like git apply care about their presence.
How It Works
After diff generation, GitAuto scans each --- and +++ line. If the file path does not already start with a/ or b/, the prefix is added automatically. The special path /dev/null is skipped, since it represents newly created or deleted files and should not have a prefix.
Before: --- src/index.ts / +++ src/index.ts
After: --- a/src/index.ts / +++ b/src/index.ts
Related Features
- Diff Hunk Repair - Fixes incorrect line counts in hunk headers
- Trailing Space Removal - Strips trailing whitespace that can also corrupt diffs
Need Help?
Have questions or suggestions? We're here to help you get the most out of GitAuto.
Contact us with your questions or feedback!