Abdul Jalil narrates from a man of Bakr bin Wa'il that he said: I was present with Ali (may Allah be pleased with him) when he was asked about a hermaphrodite (khuntha); he asked the people, and they did not know. Then Sayyiduna Ali (may Allah be pleased with him) said: If he urinates from the male organ, he is a boy, and if he urinates from the female organ, she is a girl.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الفرائض / 12515