GitPython创建和推送标签

时间:2016-03-07 14:02:46

标签: python git gitpython

在python脚本中,我尝试在git存储库上创建并将标记推送到origin。我使用gitpython-1.0.2。

我可以检出现有的标签,但无法找到如何将新标签推送到远程标签。

非常感谢

3 个答案:

答案 0 :(得分:9)

new_tag = repo.create_tag(tag, message='Automatic tag "{0}"'.format(tag)) 

repo.remotes.origin.push(new_tag)

答案 1 :(得分:2)

使用gitpython创建新标记:


     ID               Group1               Group2      Cons
0   A001           BD BD GH A           BD BD GH A  0.333333
1   A002           BD BD GH A           BD BD GH A  0.333333
2   A003           BD BD GH A           BD BD GH A  0.333333
3   A004           BD BD GH A         BD BD GH A G  0.333333
4   A005           BD BD GH A         BD BD GH A G  0.333333
5   A006           BD BD GH A         BD BD GH A G  0.333333
6   A007           BD BD GH A         BD BD GH A F  0.333333
7   A008           BD BD GH A         BD BD GH A F  0.333333
8   A009           BD BD GH A         BD BD GH A F  0.333333
9   A010                   AB                   AB  0.600000
10  A011                   AB                   AB  0.600000
11  A012                   AB                   AB  0.600000
12  A013                DF DC                   AB  0.600000
13  A014                DF DC                   AB  0.600000
14  A015                DF DC                DF DC  0.333333
15  A016  AB CDE FGHI-JSHD JS  AN CDE FGHI-JSHD JS  1.000000
16  A017         HD MV APS MG     HD NV ALS BA HDJ  1.000000
17  A018          LA JF NV WJ         LA JF NV OHB  1.000000

推送到远程

from git import Repo
obj = Repo("directory_name")
obj.create_tag("tag_name")

答案 2 :(得分:0)

我使用下面的代码片段创建了一个标签并将其推送到远程。您可能需要通过在每个 git 操作上添加 try ... catch 块来处理异常。

repo = git.Repo(os.path.abspath(repo_path)
repo.git.tag('-a', tagname, commit, '-m', '')
repo.git.push('origin', tagname)
相关问题