Pitting on a knife blade is caused by corrosion from rust and moisture. The only way to remove pitting completely is to grind down the blade metal until the surface is even. This is fine for most knives but will devalue an antique or collectable (such as a WWII German Officer's dagger or an 1830s Bowie knife), more than does the pitting. You may instead choose to polish the blade to minimise the appearance of pitting, without significantly thinning the blade.
Check the value of your knife if you have any doubt that it is collectable. Seek a professional restorer if it has significant value. The Official Price Guide to Collector Knives by C. Houston Price and Mark Zalesky is a one-stop resource for collectable knives and is available online.
Polish the blade with a quality metal polish, like NEVR-DULL, Flitz or Gold Seal Glass Wax. These will remove any oxidation and minimise the appearance of pits. Be certain to polish the spine as well. For heavy pitting, use a paste or liquid metal polish on a buffing wheel or a buffing attachment on a drill.
Lay the blade on a piece of wood, such that you cannot cut yourself on the blade. Coat the blade with WD-40 or honing oil. Polish the blade with 1-grade steel wool, which is the grade that auto shops use before priming a car for painting. Keep polishing until you are satisfied with the results; turn the blade over and polish the other side. Finally, polish the side as well.
Burnish the blade with ultra-fine steel wool (000 or 0000 grade), then use the metal or glass polish for a like-new finish.
Belt sand the blade, if the above results are unsatisfactory. Use a 320 grit belt, move on to a 600 grit for polish and a leather polishing belt to finish the blade.
Coat the restored blade with a protective finish, such as WD-40 or simple vaseline. Wipe off the excess.
Use your knife, polish it and reapply the protective coating regularly. Pitting happens when a blade is used and not cleaned or when it sits unused and unchecked.
There is no quick and easy way to restore a blade after pitting; trust that even if it appears you are making little progress, you are achieving results. It can take hours. It is tempting to use a disk sander or hand-held belt-sander in place of a stationary sander. These are fine for low-value knives, but it is difficult to achieve an even thickness or keep an even edge with anything but a belt sander. Stainless steel blades rarely pit as much as do the carbon steel and Damascus steel blades (commonly used in hunting or diving knives). If your blade is stainless steel, you will need to buff the blade to restore its shine. Use a buffing wheel or a buffing attachment on a drill, with plenty of metal polish.