One way to accomplish some of this is to copy your Project.toml to a new directory and then Pkg.instantiate()
it.
using Pkg
d = mktempdir()
cp(Base.active_project(), joinpath(d,"Project.toml"))
Pkg.instantiate()
The only way to really reset all global variables is to restart Julia.
To reset the precompile cache you need to remove the ~/.julia/compiled/v1.9
directory or subdirectories.
More precisely,
compilecache_path = joinpath(DEPOT_PATH[1], "compiled", "v$(VERSION.major).$(VERSION.minor)")