Python Web服务器中使用git自动增加版本号
我有一个本地开发的Python Web服务器(使用瓶子、烧瓶或任何其他工具):Python Web服务器中使用git自动增加版本号,python,git,git-commit,Python,Git,Git Commit,我有一个本地开发的Python Web服务器(使用瓶子、烧瓶或任何其他工具): BUILDVERSION = "0.0.128" @route('/') def homepage(): ... # using a template, and the homepage shows the BUILDVERSION in the footer # so that I always know which live version is running ... ru
BUILDVERSION = "0.0.128"
@route('/')
def homepage():
... # using a template, and the homepage shows the BUILDVERSION in the footer
# so that I always know which live version is running
...
run(host='0.0.0.0', port=8080)
每次我有重大更新时,我都会:
git commit -am "Commit name" && git push
远程版本也会更新。(注意:我在远程回购上使用了git config receive.denyCurrentBranch updateInstead)
问题:我经常忘记在每次提交时手动增加BUILDVERSION
,然后很难区分哪个版本正在运行,等等(因为两次连续提交可能具有相同的BUILDVERSION
!)
问题:是否有一种方法可以在每次使用Python+Git提交时自动增加BUILDVERSION
?或任何类似的内容(BUILDVERSION也可以是提交ID…),并以小字符显示在网站的页脚中,允许区分Python代码的连续版本。如中所述,
git,更具体地说,可以使用预提交
钩子来实现这一点
在Python的特定情况下,或可在.git/hooks/pre-commit
脚本中使用:
#!/bin/sh
bumpversion minor
git add versionfile
另一个选项是使用git提交id而不是
BUILDVERSION
:
import git
COMMITID = git.Repo().head.object.hexsha[:7] # 270ac70
(这需要pip先安装gitpython
)
然后,可以使用
git log
或git rev parse--short HEAD
(短SHA的git默认值为7位)。如果在repogit log | HEAD-1 | awk'{print$2}中运行此命令,是否获得目标上的提交ID
?@Hackerman,是的(Linux),它起作用了。在源上,没有(Windows;)。可能有重复的