Praise be to Allaah.
Everything that Allaah and His Messenger said is truth. The word ‘if’ or ‘if only’ is used in two ways:
1. To express grief for the past and distress what has been decreed. This is what is not allowed, as Allaah says (interpretation of the meaning):
“O you who believe! Be not like those who disbelieve (hypocrites) and who say to their brethren when they travel through the earth or go out to fight: ‘If they had stayed with us, they would not have died or been killed,’ so that Allaah may make it a cause of regret in their hearts”
[Aal ‘Imraan 3:156]
This is what the Prophet (peace and blessings of Allaah be upon him) forbade when he said, “If anything happens to you, do not say, ‘If only I had done such and such, then such and such would have happened.’ Say instead, ‘Qaddar Allaah wa maa sha’a kaan (Allaah decreed and what He wills happens), for ‘If only’ opens the door to the Shaytaan”, i.e., it makes you vulnerable to grief and fear, which is harmful to you and is of no benefit. Know that whatever befalls you, you could not have avoided, and whatever does not happen to you, you could not have made it happen to you, as Allaah says (interpretation of the meaning):
“No calamity befalls, but by the Leave [i.e. Decision and Qadar (Divine Preordainments)] of Allaah, and whosoever believes in Allaah, He guides his heart” [al-Taghaabun 64:11]
They said, this is a man to whom calamity happens, but he knows that it is from Allaah, so he accepts it and submits.
2. When the word ‘if’ is used to convey beneficial knowledge, such as the aayah (interpretation of the meaning):
“Had there been therein (in the heavens and the earth) aalihah (gods) besides Allaah, then verily, both would have been ruined” [al-Anbiyaa’ 21:22]
The second type is used to express love for goodness, such as saying, “If only I had what so and so has, I would do what he does.” Saying things like this is permissible.
The hadeeth of the Prophet (peace and blessings of Allaah be upon him), “If only he [Moosa] had had patience, so that Allaah would have told us more of what happened between them” is of this nature, as is the aayah (interpretation of the meaning):
“They wish that you should compromise (in religion out of courtesy) with them, so they (too) would compromise with you”
Our Prophet (peace and blessings of Allaah be upon him) wished that Allaah has told us more of their [Moosa and al-Khidr] story, and he mentioned that in order to point out his love for patience and the results that come from it, and the benefits that it can bring. There was no element of fear, grief or neglect of the duty of patience in the face of what has been decreed.
And Allaah knows best.