The secret of life. To restore someone to life, and grant them immortality, follow the instructions below.
Dfhack is only needed to make sure the character is playable after being revived, the rest of the mechanisms are strictly vanilla.
Before continuing first learn of the costs involved:
You will forget most of what you have learned in life, your skills, but also all your powers, (and the following remains untested, any necromantic arts you have learned. They are not easily retrieved either, as you will lose the skill to read. Your appearance and stats will be randomized. Still this is a small price to pay for the secrets of life.
Instructions:
These assume you have a character to help the character that you want to restore to life.
First:
1) back up your save. You are intentionally messing with bugs in the code, and it may well go wrong.
2) go to an area that animates the dead naturally. This will not work with player cast reanimation.
3) Place the corpse on the ground. If the subject is not dead yet you know what to do, but take care:
Make sure the body is in good condition, mangled corpses can not be raised.
Bodyparts can be raised, but if you return to life as a living detached hand, you will just bleed out in seconds.
4) When the body is placed you have to wait until it is animated by the surroundings. You have to wait in real time (sleeping or waiting will not do). This can take many in game days, but usually a few hours will do. It helps to overburden yourself and crawl, to make as much time as possible pass between each step.
5) When the body comes to life as a zombie, you have to make sure it is playable, because the game will have forgotten it was a player character. Use the Dfhack bodyswap command to control the character, and swap back again.
6) now you can abandon the fresh zombie, and retire your helper character.
7) unretire the revived character. This has some weird bugs and glitches! The character will be in the list of old adventurers, but not in the place you expect, and with a false name, because the game has forgotten their real name. It should be the very last name in the list, which is usually partially copied from the name above, see the picture below:

8 ) after unretiring, rename your character.
9 ) check for obvious bugs or problems. In the list of adventurers above there is another strange entry "Señamatem from Cassastuta" that appears to take part of it's name from the entries above. In this case it is was an old pet of the helper adventurer. Somehow the game has also upgraded it into an active adventurer. It's best to unretire these characters and kill/rename them.
For reference, here are the DFhack stats of the character after it is revived. Some things like the age are untouched, and the character retains it's immortality from when it was an undead. Many other things appear to be randomized:
