Don't reuse commit IDs for new commits after undo. Closes #1598.