Keep one's hair on indeed means
To stay calm or, to be patient.
History
As far as I know, it's a colloquial British English idiomatic expression, urging the other party not to lose their cool. However, it seems to have spread across the globe and is widely used across the US, Australia and other English speaking countries.
Acc. to Google Ngrams, the phrase first appears in 1868-69. To keep your shirt on has the same meaning and tone but doesn't seem to appear before 1870-71, according to Google Ngrams and in 1904 according to Etymonline.
NOTE: The expression "keep your hat on" predates them both to the year 1804.
Extended Explanation
(Disclaimer: This is some sheer guesswork, putting two and two together.)
The idiom seems to be constructed from that fact that one might lose their hair due to stress (check this), or even might pull it out in exasperation, anger or frustration.
The Ngram results definitely indicate that keep your hair on is currently more popular than keep your shirt on". And for what its worth, these expressions have nothing to do with to let your hair down.
Best Answer
see: https://en.wikipedia.org/wiki/Exception_handling at History
"... Software exception handling developed in Lisp in the 1960s and 1970s. This originated in LISP 1.5 (1962), where exceptions were caught by the ERRSET keyword, which returned NIL in case of an error, instead of terminating the program or entering the debugger.[10] Error raising was introduced in MacLisp in the late 1960s via the ERR keyword.[10] This was rapidly used not only for error raising, but for non-local control flow, and thus was augmented by two new keywords, CATCH and THROW (MacLisp June 1972), reserving ERRSET and ERR for error handling. ..."