If it becomes obvious that your current course of action will lead to defeat then retreat and regroup.
Related story
Before the Battle of Chengpu, Jin is said to have retired "three stages" (45 km) before camping on the plain of Chengpu at the border of Jin, awaiting a decisive battle and thus fulfilling Duke Wen's promise to King Cheng during his refuge in Chu. The retirement also linked the Jin forces up with Qi and Qin reinforcements.