It is narrated from Sayyiduna Qays bin al-Nu'man (may Allah be pleased with him) that "when the Messenger of Allah (peace and blessings be upon him) and Sayyiduna Abu Bakr (may Allah be pleased with him) set out to hide in the cave, they passed by a shepherd who was grazing goats. The two of them asked him for some milk to drink, and he said: By Allah! I have no goat that can be milked, except this one young goat which became pregnant at the start of winter, but now no milk is left in it and it has become completely dry. The Messenger of Allah (peace and blessings be upon him) said: 'Bring it to us.' So the Messenger of Allah (peace and blessings be upon him) prayed for blessing on it and milked it into a large bowl, then gave Sayyiduna Abu Bakr (may Allah be pleased with him) to drink; he milked again and gave the shepherd to drink; then he milked more and drank himself. At this that slave asked (in amazement): By Allah! Who are you? I have never seen anyone like you (so blessed)?! The Messenger of Allah (peace and blessings be upon him) asked: 'If I tell you, will you keep my secret?' He said: Yes. He (peace and blessings be upon him) said: 'I am Muhammad, the Messenger of Allah.' He said: Are you the one about whom Quraysh claim that you have turned away from your forefathers' religion? He (peace and blessings be upon him) said: 'Do they really say that?' He said: (If so,) then I bear witness that you are indeed the Messenger of Allah, that the teachings you have brought are true, and that what you have just done can be done by none but a Prophet. Then he said: I want to follow you. He (peace and blessings be upon him) said: 'Not yet, until you hear that we have prevailed; when that news reaches you, then come to us.' So after the Messenger of Allah (peace and blessings be upon him) had come out of the cave (and Islam had prevailed), he came to him (peace and blessings be upon him)."
The chain of this narration is sahih.