A file can be included by using PDFLaTeXs | / shellescape feature
(thanks @siracusa for pointing me to \write18 ).
Reading command output is done by using {|"script"} for the file argument
src
and these " can be replaced by using \string" to force compability with packages like ngermansrc.
A file having a specified commit can be checkedout (of a remote git repository) by using
git archive --remote=ssh://git@server/repo.git VERSION path/to/file (here VERSION can be a TAG or a commithash or just master)src.
To clean the output from the ssh connection we pipe the stderr to the trash by appending a 2>/dev/null.
As git archive generates a tar archive, we have to remove the tar headers by using tar to read from stdin - and --extract it --to-stdout: | tar --extract --file - --to-stdout src.
TL:DR
for a remote file
\lstinputlisting{|\string"git archive --remote=ssh://git@server/repo.git VERSION path/to/file 2>/dev/null | tar --extract --file - --to-stdout\string"}
for a lokal file
\lstinputlisting{|\string"git archive --remote=/path/to/.git VERSION path/to/file 2>/dev/null | tar --extract --file - --to-stdout\string"}
Useful macro for this has been worked out here
\write18approach to execute a git command that stores the specific file version in a temp file, and include it normally via\lstinputlistingafterwards. – siracusa Jul 18 '19 at 15:21