When I wash my hair and go to sleep, my hair is impossible to comb in the morning, stubbornly sticking to the shape it assumed during the night. The only way to get it right is to wet it again and comb it. What's the cause of this memory effect?
Hair, like fingernails and animal horn is made up mostly of a protein called Keratin. The strength and hardness of this polymer is caused by three types of chemical bonds: salt (ionic) bonds, hydrogen bonds and disulphide bonds. Water can significantly break the first two types (but not the disulphide ones).
Significantly wetting hair thus leads to making it more flexible and softer. But if wet and deformed hair dries it tends to retain the shape it was in while it was wet. The reformed hydrogen and salt bonds then leads to a 'permanent' deformation (until you wet it again).
As @Gert says hair is made up of the protein keratin. However, even polymeric proteins are far thinner than any strand of hair, (a few nanometers across ) and thus any individual hair must consist of many millions of keratin polymers. These will be twisted and folded back on themselves to make a hair fibre. Each segment of the keratin protein polymer has a defined structure and adding water and then removing it will reproduce the same protein back again. This is a general property of most proteins. An unfolded protein is like a random mess of amino acids with poor mechanical properties.
The most likely explanation of the hair whetting/setting/drying process is that hair is treated as a material, then adding water enters the material, but not necessarily any protein, and allows regions of the material to slide past one another under the influence of a force. They then maintain their new geometry, after water evaporates and the forces applied to them by combing, lying on a pillow, etc. are removed. Whetting again allows inter-strand movement and so the hair can have a new shape, alternatively adding a cosmetic polymer restricts movement and allows hair to take on other shapes. In my case, my hair is so short that it sticks up whatever I do to it and this supports it being treated as a material rather than a molecule!