Holen Sie sich Git Sha

def get_git_sha():
    locations_to_try = ['git', '/bin/git', '/usr/bin/git', '/usr/local/bin/git']
    git_binary, sha, timestamp = None, None, None
    for location in locations_to_try:
        sha = os.popen(f'{location} rev-parse HEAD').read().strip()
        if (len(sha) > 10) and ' ' not in sha:
            git_binary = str(location)
            break
    if not sha:
        return None
    timestamp = os.popen(f"{git_binary} show --no-patch --no-notes --pretty='%at' {sha}").read().strip()
    timestamp = str(datetime.fromtimestamp(int(timestamp)))
    return git_binary, sha, timestamp
Envious Echidna