t3508: add check_head_differs_from() helper function and use it