That's happened to me a few times throughout my life, and it's always difficult. I usually pull out of it by listing out the things in my life that are making me unhappy. Deep, root issues, like social isolation, doubting my worth, losing my dreams, and other things that I'm just not happy with in life. Usually, that list isn't easy to generate, because I feel trapped in such a way that there doesn't always seem to be an alternative to the way things are now. It's like trying to think, "I wish it would be lighter out," when I can only conceptualize darkness. It just doesn't even cross my mind. But then I do my best to affect a change, by finding ways to prove my worth to myself and such. Maybe taking baby steps at first, even when I don't think it'll help. Sometimes it takes me weeks just to get started, but when I get into the swing of things and start seeing that I'm not as trapped as I thought I was, the depression usually starts fading. From then on, it's a matter of reassuring myself and doing general life maintenance so I don't sink back into that state of mind.
Sometimes it means I need to give something up that I've loved for a long time, too. Certain obsessions, certain dreams or projects... sometimes even people. In those situations, it's about learning to just let go and follow my heart to where it really wants to be.
I hope that helps you.