make rebase more robust such that it never leaves a working copy in a bad

state