“You saw with your own eyes what Hashem did in the matter of baal-peor, that Hashem wiped out from among you every person who followed baal-peor; while you, who hold fast to Hashem, are all alive today.” (Devarim 4:3-4)
These Pesukim tell us that those that worshipped baal peor (an idol) were wiped out, but those “who hold fast to Hashem, are all alive”. The words “who hold fast to Hashem” are a translation of the word “הַדְּבֵקִים” which is the word used in the Possuk above. “הַדְּבֵקִים” has a deeper meaning in the Torah than what the English translation conveys. “הַדְּבֵקִים” really refers to a cleaving to Hashem – a special, close relationship between Hashem and an individual. The Pesukim however, do not tell us how to achieve that special relationship, the one that spelled the difference between worshiping baal peor (death), and following Hashem (salvation). How does one achieve this close relationship with Hashem?
The Chida in his Sefer entitled, “Yoseph Tehilos” offers the following insight. The Chida explains that the words in the Passuk do indeed inform us how to achieve this relationship. It is alluded to with the word that proceeds “הַדְּבֵקִים” in the Passuk which is “וְאַתֶּם“. If you take this word (minus the prefix “vav”) and rearrange the letters you get “אמת“ (truth). The Passuk is telling us that the way to achieve “הַדְּבֵקִים” that special closeness and cleaving to Hashem, is through “אמת” - by being truthful people.
It bears mentioning that the Chida also writes that the way to Teshuva (repentance) is also through truth. In his explanation of the Passuk, “You, Hashem, are near, and all Your commandments are true.” (Tehillim 119:151) he cites the Sefer Chassidim which discusses a certain evil person who approached a Gadol (a wise, pious individual) and asked him how to do Teshuvah, but not to burden him with excess requirements. The Gadol responded to him with only one requirement: “Grab onto the Middah of truth. Agree to be honest in all of your undertakings.” The person agreed and went on his way. One day, his Yetzer Hara (evil inclination) took hold of him. He planned to steal every item from the home of a certain wealthy person. While he was on his way to commit the crime, someone asked him where he was going. Since he had agreed to tell the truth in all of his undertakings, he would have to tell the truth about what he was about to do. However, this would have caused him great embarrassment. He therefore decided that he would not steal. This repeated itself in different contexts with different sins that he wished to commit but didn’t, because of the embarrassment it would have caused him when forced to tell the truth about them. Since he committed to always tell the truth he could no longer sin and he did Teshuva.