Monday, 15 April 2013

Get the current git hash in a python script -



Get the current git hash in a python script -

i include current git hash in output of python script (as 'version number' of code generated output).

how can access current git hash in python script?

the git describe command way of creating human-presentable "version number" of code. examples in documentation:

with git.git current tree, get:

[torvalds@g5 git]$ git describe parent v1.0.4-14-g2414721

i.e. current head of "parent" branch based on v1.0.4, since has few commits on top of that, describe has added number of additional commits ("14") , abbreviated object name commit ("2414721") @ end.

from within python, can following:

import subprocess label = subprocess.check_output(["git", "describe"])

python git

No comments:

Post a Comment