In tutour, I've started down the path of annotating SHAs after the fact, but another approach (almost the dual) would be to write a literate program containing diffs and then being able to generate the code at any step from there.
It's more natural in some respects but more cumbersome in others.