GitAuto Logo
  1. Home
  2. Pricing
  3. Docs
  4. Dashboard
  5. Blog
  6. Contact
  1. Home
  2. How It Works
  3. Use Cases
  4. Pricing
  5. Docs
  6. Dashboard
  7. FAQ
  8. Blog
  9. Contact

Diff Hunk Repair

GitAuto automatically recalculates and repairs incorrect line counts in unified diff hunk headers (@@ -X,Y +A,B @@). The model frequently gets these counts wrong because it cannot reliably count lines, making this one of the most common failure modes in AI-generated diffs.

Why This Exists

When the model generates a unified diff, it must specify how many lines are removed and added in each hunk header. For example, @@ -1,5 +1,7 @@ means 5 lines from the original and 7 lines in the new version. The model routinely miscounts these numbers, especially in larger hunks. When the counts are wrong, git apply silently fails or corrupts the file. Before this fix existed, wrong hunk counts were the single largest source of failed file edits.

Why Models Miscount Hunk Headers

Models generate diffs token-by-token and cannot reliably count how many lines appear in each hunk. The hunk header (e.g., @@ -1,7 +1,9 @@) requires knowing the exact line count before the content is generated, but the model writes the header first and the content after. It is predicting the count before it knows what it will write. Benchmarks evaluate whether the final code is correct, not whether the diff format is valid, so models are never penalized for malformed hunk headers during training.

How It Works

After the model produces a diff, GitAuto runs a repair pass that uses regex to find each @@ hunk header, then counts the actual context lines (lines starting with a space), removal lines (starting with -), and addition lines (starting with +) in the hunk body. It rebuilds each header with the correct counts.

Before: @@ -1,5 +1,7 @@ (wrong count)

After: @@ -1,5 +1,8 @@ (correct count)

This repair runs automatically on every diff before git apply is called, requiring zero agent iterations and zero additional API calls.

Related Features

  • Diff Prefix Repair - Ensures proper a/ and b/ prefixes in diff file paths
  • Tool Argument Correction - Detects when diff arguments are sent to the wrong tool

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!

Coding StandardsDiff Prefix Repair

Getting Started

  • Installation
  • Setup

Triggers

  • Overview
  • Schedule Trigger
  • Test Failure Trigger
  • Review Comment Trigger
  • Dashboard Trigger

Coverage Dashboard

  • Overview
  • Python Testing
  • JavaScript Testing
  • Java Testing
  • Go Testing
  • PHP Testing
  • Ruby Testing
  • Flutter Testing
  • Multi-Language
  • Coverage Charts

Customization

  • Repository Rules
  • Output Language
  • GITAUTO.md

Integrations

  • CircleCI Integration
  • npm Integration

How It Works

Context Enrichment

  • Line Numbers
  • Full File Reads
  • Test File Preloading
  • Test Naming Detection
  • Error Baselines
  • CI Log Cleaning
  • Trigger-Specific Prompts
  • Coding Standards

Output Auto-Correction

  • Diff Hunk Repair
  • Diff Prefix Repair
  • Tool Name Correction
  • Tool Argument Correction
  • Import Sorting
  • Trailing Space Removal
  • Final Newline
  • Line Ending Preservation
  • Sanitize Tool Arguments
  • Lint Disable Headers

Quality Verification

  • Formatting
  • Linting
  • Type Checking
  • Test Execution
  • Coverage Enforcement
  • phpcs / phpstan Support
  • PHPUnit Support
  • pytest Support
  • Snapshot Auto-Update
  • Untestable Detection
  • Should-Skip Detection
  • Dead Code Removal
  • Quality Check Scoring
  • Quality Checklist

Safety Guardrails

  • File Edit Restrictions
  • Temperature Zero
  • PR/Branch Checks
  • Race Condition Prevention
  • Bot Loop Prevention
  • Webhook Deduplication
  • Duplicate Error Hashing
  • Infrastructure Failure Detection
  • Strict Tool Schemas
  • No-Change Detection

Token/Cost Management

  • Token Trimming
  • Outdated Diff Removal
  • Stale File Replacement
  • Skip CI Intermediate
  • CI Log Deduplication
  • Web Fetch Summarization
  • Context Forgetting
  • File Query Routing
  • On-Demand Diff

Resilience & Recovery

  • Model Fallback
  • Overload Retry
  • Forced Verification
  • Error Files Editable

Hallucination Prevention

  • Web Search
  • URL Fetching
  • Anti-Hallucination Prompts
  • GITAUTO.md Restrictions
  • Review Response Guardrails

Ready to improve your test coverage?

Go from 0% to 90% test coverage with GitAuto. Start for free, no credit card required.

Install FreeContact Sales

Product

  • Home
  • Why GitAuto
  • What GitAuto Does
  • How It Works
  • Use Cases
  • How to Get Started
  • Solution
  • Pricing
  • Pricing Details
  • ROI Calculator
  • ROI Methodology
  • FAQ
  • Blog
  • Contact

Dashboard

  • Dashboard
  • Coverage Trends
  • File Coverage
  • Credits
  • Open PRs
  • Usage
  • Triggers
  • Actions
  • References
  • Rules
  • CircleCI Integration
  • npm Integration

Documentation

  • Docs
  • Getting Started
  • Setup
  • Triggers
  • Coverage Setup
  • Customization
  • How It Works
  • Auto Merge
  • CircleCI
  • npm

Legal

  • Privacy Policy
  • Terms of Service

Connect

  • GitHub
  • LinkedIn
  • Twitter
  • YouTube
GitAuto Logo© 2026 GitAuto, Inc. All Rights Reserved