Don't use
any command or 'tool' if you don't know what it does ... would be a more accurate statement. There's no easy and fast way out of this jungle, I'm afraid.
You have to make some choices here:
don't mix portmaster and portupgrade, they don't share any information, so they both lose track of what you (de)install if you mix them. This will lead to all kinds of errors about missing ports, already installed ports, or other problems.
Only use a mix of ports and packages if you understand the difference and if you're able to resolve problems, like version discrepancies, dependency problems, etc.
If you have a reasonably fast computer, I advise you to run a ports-only system using portmaster. If you don't have a lot of processing power, stick to packages only, and use portupgrade
-PP exclusively to maintain them, or use tools in
sysutils/bsdadminscripts to keep packages up to date.
To get out of this mess (if you have the time to do so, and I'm assuming you'll want to use ports), I'd suggest running [cmd=]portmaster -L[/cmd], making a note of the
'root ports' (first block of output) and the
'leaf ports' (last block of output), and run [cmd=]portmaster -Rf[/cmd] on each of the ports in those two categories. This will reinstall everything, dependencies included.
Make sure you have an
up-to-date ports tree before you start this process, and make sure your ports tree is always up to date whenever you install/upgrade/replace any port.
Another option would be to tun [cmd=]pkg_delete -f[/cmd] on every port showing up in pkg_info and starting all over again. You will still need the list of root and leaf ports.
Tip: install
ports-mgmt/psearch first, and use the psearch command to find the port directory for any port. Then use a command like [cmd=]portmaster category/portname[/cmd] to install a port (e.g. [cmd=]portmaster www/apache22[/cmd]. This replaces the 'make install clean' command.
Note:
If you want to make a final 'all or nothing effort' on your installed ports as a last resort
now, run [cmd=]rm /var/db/pkg/pkgdb.db && pkgdb -u[/cmd] and try [cmd=]portupgrade -a[/cmd] if you manage to resolve all of the errors you're likely to get from the pkgdb command. If that works somehow (magically), then stick with portupgrade. If not, all of the above applies.
Oh, and
The Handbook is your friend, as always. I'm bowing out of this topic now, enough time invested .. I'm not going to write a separate Handbook.