On the recommendation to repeat the greeting to the one he meets after a short time since he has come in or gone out and then returned immediately, or a tree or the like has come between them

Riyad as-Salihin (The Meadows of the Righteous)

by Imam Nawawi

134. Chapter: On the recommendation to repeat the greeting to the one he meets after a short time since he has come in or gone out and then returned immediately, or a tree or the like has come between them

859. Abu Hurayra reported in the hadith about the man who prayed badly when he came and prayed and then he went to the Prophet and greeted the Prophet who returned the greeting and said, "Go and back and pray. You have not prayed." He went back and prayed as he had prayed before. Then he came and greeted the Prophet, may Allah bless him and grant him peace, until he had done that three times. [Agreed upon]

860. Abu Hurayra reported that the Messenger of Allah, may Allah bless him and grant him peace, said, "When any of you meets his brother, he should greet him. If a tree or a wall or a stone comes between them and then he again meets him, he should greet him again." [Abu Dawud]