According to the [Patanjali Yoga Sutras (with translation and commentary by Swami Vivekananda)][1] a Yogi can know past and future by employing a technique called Samayana. To know what Samayana is you just need to go through the Vibhuti Pada section of that text.

In short, Dharana, Dhyanam and Samadhi, when done at the same time, is called Samayana.
 

Sutra 16 of this Chapter states:
 

> parinamatrayasanyamadatitanagatajnanam ||
> 
> By making Samyama on the three sorts of changes comes the knowledge of
> past and future

 
Sutra 18 again says:

 

> sanskarasakshatkaranat poorvajatijnanam ||
> 
> By perceiving the impressions, knowledge of past life.
 
The commentary on this verse by Swami Vivekananda is as follows:


> 
> Each experience that we have comes in the form of a wave in the
> Chitta, and this subsides and becomes finer and finer, but is never
> lost. It remains there in minute form, and if we can bring this wave
> up again, it becomes memory. So, if the Yogi can make a Samyama on
> these past impressions in the mind, he will begin to remember all his
> past lives.

 
Apart from that, according to Manu Smriti, one can acquire the faculty of remembering one's past lives even by performing Vedic studies, austerities etc. Here is the verse:
 

> Manu Smriti 4.148. By daily reciting the Veda, by (the observance of
> the rules of) purification, by (practising) austerities, and by doing
> no injury to created beings, **one (obtains the faculty of)
> remembering former births.**


  [1]: http://www.yogaincentro.it/uploads/file/PatanjaliYogaSutraSwamiVivekanandaSanEng.pdf