Skip to content

Instantly share code, notes, and snippets.

@onlyyoujack
Forked from bitrut/last_commit.py
Created May 17, 2016 14:59
Show Gist options
  • Save onlyyoujack/f96f6b564810ce8ba970c3b61c0422f8 to your computer and use it in GitHub Desktop.
Save onlyyoujack/f96f6b564810ce8ba970c3b61c0422f8 to your computer and use it in GitHub Desktop.
Get timestamp of the last commit in git repository
#!/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())
@onlyyoujack
Copy link
Author

!/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment