Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Web服务器中使用git自动增加版本号_Python_Git_Git Commit - Fatal编程技术网

Python Web服务器中使用git自动增加版本号

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

我有一个本地开发的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

...

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位)。

如果在repo
git log | HEAD-1 | awk'{print$2}中运行此命令,是否获得目标上的
提交ID
?@Hackerman,是的(Linux),它起作用了。在源上,没有(Windows;)。可能有重复的