'Zaporozhians', the huge painting (2.03 × 3.58 m) by Ilya Repin, first exhibited in 1891, almost instantly became an iconic representation of Russia and Russians throughout the world, even though the cossacks in the picture are very Ukrainian.
Russians of that period (1676) wore beards and long hair. But the cossacks in the picture are all cleanly shaven, beards and heads, with just the moustaches and the khokhols, locks of hair on top of their heads. That is what Ukrainians did and it was one striking difference between the two people. And that is why their Russian nickname - khokhly.
It hardly mattered at the time when Repin painted - Russia and Ukraine were one country. It does now. Even attitudes to khokhol as a nickname vary wildly and are often very emotional. Russians rarely put any derision in the word, but Ukrainians sometimes feel it is pejorative.
It seems to me that Ukrainians living among Russians or close to Russia are happy with the word (e.g. East Ukrainians, East meaning to the East of the Dnieper river). They happily tell khokhol jokes, whith the хохол cleverly tricking the Russian, but also with a self-mocking attitude. Think Irish jokes. The main character in The Ninth Company, a Soviet army seargeant in Afghanistan, is called Khokhol by his multiethnic unit and is happy wearing the nickname. On the other hand, West Ukrainians (zapadnetsy - западнецы) are more sensitive to the term and often do see it as pejorative.
The difference seems to stem from that the хохол appeared as a Russian exoethnonym for Ukrainians as a reference to their tradition of shaving beards and heads, leaving moustaches and topknots (khokhol, or chub or oseledets), while Russians were wearing beards. Happy co-existence lead to adoption of the exonym for self-identification (East), strife lead to negative attitudes to the term (West).
It's difficult to understand these subtleties if you are outside the 'soup' where nationalistic emotions brew. Repin was indeed criticised for not being 'historically accurate' and started painting a new version of the picture - where cossacks all have beards! Curiously, the two 'Ukrainian' versions are now in the two top Russian museums - Russky Muzey in Petersburg and Tretyakov Gallery in Moscow, but the 'Russian' version is in Kharkov, Ukraine.
'Reply of the Zaporozhian Cossacks to Sultan Mehmed IV of the Ottoman Empire' (1893, unfinished):