tl;dr - There was no way (a debatable point) to undo the events of the timeline as we saw it, but they could sneak over to other timelines and fix the majority of the effects of The Snap.
The main problem is the somewhat confusing theory of time travel that the movies used, which is based on at least A version of time travel the comics have used.
According to the explanation, when you travel in time, you do not travel into your own past, but into an alternate timeline in which your appearance took place. So taking the stones out of the timeline does not erase their existence in "our present", and does not negate Thanos being able to retrieve them.
So the recovery missions generate several new timelines where each of the stones no longer exist where they did in the main timeline.
But by returning the stones almost immediately after they were removed, the effect on said timelines is virtually nil. So for example, the Ancient One only loses the use of the Time Stone for a brief period, not long enough to fail to defend the Sanctum.
Thanos' time trip generates another timeline, one where he simply and mysteriously blinked out of existence. That timeline never saw him collect the stones, and never suffered through The Snappening. The Thanos we saw at the end of the film was not the same Thanos we saw at the beginning, but one from a divergent timeline.