-
-
Save onlyyoujack/f96f6b564810ce8ba970c3b61c0422f8 to your computer and use it in GitHub Desktop.
Get timestamp of the last commit in git repository
This file contains 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
#!/usr/bin/python | |
import subprocess | |
import re | |
from optparse import OptionParser | |
def git_version(): | |
p = subprocess.Popen(["git", "log" , '-1', '--date=iso'], stdout=subprocess.PIPE) | |
out, err = p.communicate() | |
m = re.search('\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}', out) | |
return m.group(0) | |
usage = "usage: %prog -f filepath" | |
parser = OptionParser(usage=usage) | |
parser.add_option("-f", default='version.py') | |
(options, args) = parser.parse_args() | |
path = options.f | |
with open(path, 'w+') as f: | |
f.write(git_version()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!/bin/bash
git 版本数
VERSION_NUMBER=
git rev-list head | sort | wc -l | awk '{print $1}'
VERSION_HASH=
git rev-list head | head -1
echo $VERSION_NUMBER
最后一次提交的hash
LAST_COMMIT_HASH=
git log -1 --pretty=format:"%h"
LAST_COMMIT_DATE=
git log -1 --pretty=format:"%cd"
LAST_COMMIT_TIMESTEP=
git log -1 --pretty=format:"%ct"
NEWDATE=
date -r $LAST_COMMIT_TIMESTEP +%y%m%d
M="1.0"
VERSION_GIT=$M.$NEWDATE.$LAST_COMMIT_HASH
echo $LASTCOMMITHASH
echo $LAST_COMMIT_DATE
echo $LAST_COMMIT_TIMESTEP
echo $NEWDATE
echo $VERSION_GIT