Python
파이썬으로 깃 해쉬 코드 얻기
파이스탁
2022. 2. 4. 10:02
간혹 파이썬 코드 내에서 현재 git repository의 hash 코드를 얻어야 할 때가 있습니다. 이때 다음과 같이 subprocess 모듈을 사용할 수 있습니다.
import subprocess
def get_hash():
cmd = "git rev-parse HEAD"
result = subprocess.run(cmd, shell=True, capture_output=True)
hash = result.stdout.decode('utf-8').strip()
return hash
git_hash = get_hash()
print(git_hash)