Distance Calculation and Recover previous commit problem