I have heard that if you drink a lot of water as a habit, the body
doesn't do much retention.
That just means that your body will not retain excessive water.
Therefore, if you are preparing for a hiking in the desert where not
much water will be available, is lowering the water intake a few days
before the hike a better approach to deal with the situation by
adapting gradually to the extreme conditions?
No. When you drink too little and become dehydrated, your body will start to inhibit sweating and urination, but you don't want to make yourself intentionally dehydrated before going to desert.
Can you improve water retention by diet?
Yes, to improve water retention, avoid high amounts of protein, which, when metabolized, produces urea, which drags water with it when excreted into urine. For example, eating 100 g of protein (100 g of cheese + a 120 g can of fish + a 150 g can of soybean + 500 mL of milk) can result in loss of ~800 mL of urine (NAP.edu).
Can you improve water retention by certain supplements?
Probably not in a hiking-through-desert scenario. Glycerol and hypertonic beverages high in sodium temporary (for few hours) increase water retention but do not decrease your water needs (Medicine and Science in Sports and Exercise).