In the Middle Ages, for example, giving money to "the poor" (whether that meant the actual poor, or the so-called 'spiritually poor'/religious communities) had a lot to do with personal benefit--helping secure easier passage through purgatory through penance for sins. Plenty of that persists today (including within humanitarian efforts!), but there is also a sense of "giving for the good of the world", anonymous donations, etc. Where does that sense of 'all humans in it together' come from?
This is a somewhat abridged version of the history of humanitarianism until the interwar period (I decided not to go on as it is already quite long), I hope it answer the question sufficiently and clearly. :)
There is not now, nor has there ever been a kind of "egalitarian" or "idealistic" humanitarianism. That's an elaborate marketing ploy and just the same kind of thing that people tell themselves to feel good. There have however, been significant changes in ethics and practicalities of how these things work that make it seem so.
Compassion (so the motivation behind "giving" in many ways), moved from the private to the more public realm at the start of the 18th century. It has been linked to globalization in the 17th/18th century. It has also been linked to the religious efforts of Latitudinarian preachers who were trying to combat the pessimistic puritan doctrines about human nature by pushing doctrines of sympathy and benevolence to show the good sides of human nature. Similarly, Enlightenment doctrines have been linked to a change in the practicalities of how compassion is enacted. (Barnett 2011, Introduction and Chapter 1)
The history of "thought" is of course tied to the history of philosophy and I don't know enough about Nietzsche and co, rather I would consider how actual events and ways of doing things show a change in compassion from charity to humanitarianism. This is made slightly more difficult because humanitarianism does not have a concrete definition that everyone can agree on. However, one of the most wide-spread definitions involves helping "others", with "others" being those who are unlike ourselves. [Side note: I am for example most interested in how compassion for the enemy created new networks of compassion/humanitarianism after WWI. Some more on that later.]
In the 19th century also saw what can be considered the logical extension of an increasingly culture of charity combined with changes in "rational" thinking/scientific thought. This was the desire to eradicate the causes of suffering. Again, while some charity organizations looked further afield, most focused on, for example, improvement for the poor at a local level. This was an especially popular pasttime for wealthy women in England.
In many ways, colonialism and alongside it, missionaries, were forerunners of humanitarianism also. It set the "stage" so to speak, of "intention" (based on for example, the "white man's burden" line of thinking along with a large dose of racism). This is of course not excusing the effects of colonialism. (The anti-slavery movement is sometimes mentioned but more commonly part of the human-rights movement history, rather than the history of humanitarianism so again, I know little about it.)
The first instance of "humanitarianism" as we would recognize it today, in most histories is Henry Dunant's founding of the Red Cross after coming across fields of wounded soldiers after the battle of Solferino (mid-19th century). Dunant was Swiss, the battle had been between French and Austro-Hungarian troops. Charity, as we all know, begins at home. Unlike the religious kind of charity done for "saving your soul" which was predominantly local, and of course the increasing value of the nation-state, Dunant went on to found the ICRC (International Committee of the Red Cross, slightly different to the IFRC, the International Federation of Red Cross and Red Crescent Societies). This was the first non-state organization designed to help but, despite Dunant's inspiration at the Battle of Solferino, the IFRC Societies predominantly worked to help wounded soldiers of the Societies own country. (Dunant 1939, Barnett 2011, Davey et al 2013)
It was during and just after WWI that things really started changing and we move away from the charity based dialogue towards a more "rights-based" dialogue. This is presumably what you mean by your question though, as many things are, these words are incredibly contested within the community (paternalism is still ever-present and a "big (bad) deal" as are ideas of equality and lack thereof). I'm also treading lightly on the "rights-based" idea of humanitarianism in the early 20th century as many people consider "rights" (like, most obviously, human rights) to only have become influential later in the 20th century and, maybe more importantly, the relationship between humanitarianism and human rights activism is not necessarily friendly as they often pursue different goals.
Nevertheless, with WWI and the changes in warfare this brought along (not least the scale), the IFRC came into its own as well as new organizations. Just prior to this, forerunners of these organizations had been founded during the Boer War (e.g. Emily Hobhouse's work against concentration camps) and the Macedonian War. During the war, Relief for Belgium was founded to help Belgian refugees. Then, shortly after the war, Save the Children (now one of the largest humanitarian organizations) was founded.
These organizations can, in my opinion, be roughly split into four camps: religious groupings (Quakers aka Society of Friends, Catholic groupings etc), political (mainly peace) activists (Women's International League for Peace and Freedom, Women's Suffrage Alliance), transnational rights-based organizations (Save the Children) and state-associated organizations (American Relief Administration under Henry Hoover). Of course, these often overlapped - Eglantyne Jebb founded Save the Children and was also involved with the Women's International League of Peace and Freedom, her sister and co-founder of Save the Children was a Quaker (and married to politician Charles Buxton, himself an outspoken proponent of a better treatment of German civilians after WWI). (Mullen 2010)
Most notably, in Britain, these activists campaigned for people who had previously been their enemies. This was in many ways the origin of much of the language and imagery we see around humanitarianism today (e.g. the "starving child", the child as an innocent etc) - the most prominent early example is the starving baby leaflet distributed by Eglantyne Jebb (and which she was arrested for as it was pro-German propaganda in 1918 when the war hadn't officially ended).
Eglantyne Jebb was also responsible for the Declaration of the Rights of the Child adopted by the League of Nations in 1924, which, together with an increase in refugee rights (e.g. introduction of Nansen Passport), was in many ways the start of a more rights based humanitarianism.
Of course, later 20th century humanitarianism still massively struggled with power-dynamics, paternalism and many other issues but I'll leave the story here as the interwar period is typically considered the start of humanitarianism as we know it today.
Barnett, Michael, Empire of Humanity, Cornell University Press, 2011
Dunant, Jean Henry, A Memory of Solferino, English translation of Un Souvenir de Solférino. Washington, D.C., American National Red Cross, 1939.
Mullen, Kate, The Woman Who Saved the Children, Oneworld Publications, 2010
Davey, Eleanor; Borton, John; Foley Matthew, A history of the humanitarian system: Western origins and foundations, Research reports and studies, June 2013 https://www.odi.org/publications/7535-global-history-humanitarian-action