If you know ahead of time that you'll want to do this, you can do the
source command in a subshell, and revert its effects (insofar as they're scoped to setting shell or environment variables) by exiting that subshell.
Thus, if you run:
(source set-variables; run-command-with-variables); run-command-without-variables
run-command-with-variables will have those variables set, but
run-command-without-variables will not.
It's also possible to identify which shell functions were set by sourcing a script by checking metadata associated with those functions, such that one could theoretically write a shell function or sourceable script that unsets all other functions defined within a given (parameterized) file. For non-function variables, however, there is not information stored to permit them to be unset (much less identifying prior values).