His saying: "Verily Allah has ordered that the good and the bad things be written down." His writing down good and bad deed encompasses two meanings:
The first meaning: His writing both in the Lawh ul-Mahfuz (Preserved Tablet) because Allah – the Exalted - has written everything in it. Allah – the Mighty and Sublime - says:
"Verily, We have created all things with Qadar (divine preordainment)" (Al-Qamar: 49).
And He, the Exalted, says:
"And everything, small or big, is written down [in Lawh ul-Mahfuz]" (Qamar: 53).
So, Allah – Glorious is He and Exalted - has written the evil and the good deeds in the Lawh ul-Mahfuz. When the servant performs them, Allah – the Exalted - records them according His Wisdom, Justice and Favor.
So, these are two forms of writing:
An Earlier Writing: No one knows it except Allah, the Mighty and Sublime. Each of us does not know what Allah has written down for him of good or evil until that thing occurs.
A Later Writing: When the individual performs an action, it will be written for him according to (Allah's) Wisdom, Justice and Bounty. "Then he explained it"; i.e., the Prophet (ﷺ) explained how it is written. He (ﷺ) explained that if a person desires a good deed but he is unable to do it, Allah - the Exalted - will record it as a complete good deed.
An example of this is: A man who resolved to perform the Ablution in order to recite the Qur'an but did not do that; he rather did something else. A complete good deed will be written for him for that.
Another example: A man resolved to give charity and even indicated the money he wanted give out. However, he later withheld the money and did not give it as charity. A complete good deed will be written for him for that.
Likewise if he intended to perform two units of Prayer but later held back not performing it. A complete good deed will be written for him therewith.
If someone says: Why will a good deed be recorded for him while he has not done it? The response is that: Allah's bounty is vast; his resolve will be recorded as a good deed because the heart is full of contemplations; good or bad. Therefore, he resolves to do a good deed, it is good and it will be written for him. But if he performs it, Allah will record it as ten good deeds to seven hundred and even greater multiples.
This variation (in rewards) is based on the level of sincerity and conformity. The more a person is sincere towards Allah in his worship, the more the reward he earns. Likewise, the more he follows the Prophet (ﷺ) in his worship, the more the worship becomes perfect and the more the reward. So, this variation is based on the level of sincerity and conformity with the Prophet (ﷺ) in the deed.
As regards evil deed; he said: "...but if he intends to do evil act and has not done it, then Allah will write it down with Him as a complete good deed..." For instance, a man resolved to steal but remembered Allah, the Mighty and Sublime -, was overwhelmed by the fear of Allah and then refrained from stealing. A complete good deed will be written for him thereof because he refrained from a disobedient act for the sake of Allah. So he will be rewarded for that as is contained in another version of the hadeeth, "...because he refrained from it out of fear for me..."(1) i.e., for my sake.
He had decided to commit a sin – for example - backbiting, but he remembered that it is forbidden and so, refrains from it for the sake of Allah; He will certainly be given a complete good deed thereof.
But if he does an evil deed, only it will only be written down for him as a single sin. Allah – the Most High – says:
"Whoever brings a good deed shall have only the recompense of the like thereof and they will not be wronged" [Al-An'am: 160].
This hadeeth contains: Proof for the significance of intention, and that intention would bring the individual to good.
It had been explained that if an individual intends evil and performs an action that leads to the evil but is unable to do it, the sin of a person who did the evil will be written for him as was mentioned regarding the two Muslims who face one another with their swords, "When two Muslims face each other with their swords (ready to fight), the killer and the slain are both in the hell!" They said: "O Messenger of Allah! As for the killer, it is understandable, but why the slain one?" He said, "He was eager to kill his opponent [too]."
And Allah is the source of success.