How to use the python subprocess to get the latest commit id from master(git repo)

hari Source

I am unable to get the latest commit id from the master using the python subprocess task . Please note the details below.

Script details:

Release_Commit_result= subprocess.check_output("git", "log", "-1", "--pretty=format:","%H")

when I ran the script, I am getting following out put as,


Release_Commit_result= subprocess.check_output("git", "log", "-1", "--pretty=format:","%H")

File "/usr/lib/python2.7/", line 212, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)


init() got multiple values for enter code herekeyword argument 'stdout'

This git command alone actually gives the out put when it ran from the git bash.



answered 2 weeks ago primef #1

Execute the command giving the arguments in an array or in a single string. Like this:

subprocess.check_output(["git", "log", "-1", "--pretty-format:%H"])

Please see as reference.

UPDATE Edited command according to phd's suggestion, in the comments.

comments powered by Disqus