Created
June 29, 2014 02:56
-
-
Save ethanwhite/ba63849c26301f862e4e to your computer and use it in GitHub Desktop.
Get hash of current git HEAD using Python built-ins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
process = subprocess.Popen(['git', 'rev-parse', 'HEAD'], shell=False, stdout=subprocess.PIPE) | |
git_head_hash = process.communicate()[0].strip() |
Windows 10 ok
MacOS 12.4 OK
(b'', None) doesnt work anymore
ubuntu 22.04
Still works for me. Also on Ubuntu 22.04. Python 3.10.10.
Python 3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>>
>>> process = subprocess.Popen(['git', 'rev-parse', 'HEAD'], shell=False, stdout=subprocess.PIPE)
>>> git_head_hash = process.communicate()[0].strip()
>>> git_head_hash
b'37982577eca010a03dd5b5e23fe30be8f42da9ed'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on both Ubuntu 14.04 and Windows 7.