Transition between fermentation and respiration determines history-dependent behavior in fluctuating carbon sources