Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to extract the git repo revision hash via Python code?

Are there any easy ways to grab the git repository (on GitHub) version hash with Python code? I want to use this to handle versioning of 'dev' releases of my software on github.

like image 802
Christopher Dorian Avatar asked Nov 23 '25 02:11

Christopher Dorian


1 Answers

def git_version():
    from subprocess import Popen, PIPE
    gitproc = Popen(['git', 'rev-parse','HEAD'], stdout = PIPE)
    (stdout, _) = gitproc.communicate()
    return stdout.strip()
like image 52
deddu Avatar answered Nov 25 '25 14:11

deddu