## TL;DR

Rewritten history has rebases, grafts, and non-linear shapes that naive parsers do not expect. Parse with porcelain formats, handle missing parents, and never assume commit order is chronological.

## Error

```text
agent's git log parser broke with error on rewritten history
```

## Steps

1. Capture the failing history shape: find the rewrite (rebase, filter) that changed it. Expected: the trigger identified.
2. Switch parsing to a stable porcelain format with explicit fields. Expected: machine-readable output.
3. Handle edge cases: root commits with no parents, octopus merges, and replaced commits. Expected: no assumptions about shape.
4. Validate the parser against a rewritten-history fixture. Expected: proven robustness.
5. Re-run on the real repo. Expected: clean parse.

## When to use

- Git log parsers breaking after history rewrites.
- Building history-analysis agents.

## When not to use

- Empty or corrupt repos (different problem).
- The parser works but is slow (performance issue).

## Tool compatibility

- Git porcelain log formats; agent parsers.

## Variant phrasings

### git log parse failed after rebase

Defensive parsing.

### parser broke on rewritten history

Same fix.

## Why it happens

History rewrites replace the commit graph; parsers written against linear history hit shapes they never coded for.

## Edge cases

- Shallow clones have grafted roots; treat them like rewrites.
- Replaced commits (git replace) change the graph without rewriting.
- Timestamps are unreliable for ordering; use topology.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_H4wSHGQrfm5O6SX26nbeQw
