如何使用 gitpython repo.archive() 作为标签

howto use gitpython repo.archive() for a tag

我必须导出标签的特定路径。 git 命令是 git archive <tag> 但我没有找到用 gitpython

做到这一点的可能性

我试过了

repo.archive(tar, "<tag>")

运气不好。

import git
import os.path

repopath = '/path/to/repo'
repo = git.Repo(repopath)
repo.git.archive('<tag>', '-o', '<tag>.zip')
if os.path.exists('<tag>.zip'):
    pass

您可以将几乎所有 git 命令翻译成 repo.git.<cmd>(arg0, arg1, ...)。需要将命令名称中的-替换为_.

git log --oneline    ->    output = repo.git.log('--oneline')
git commit --allow-empty -m "foo bar" ->  output = repo.git.commit('--allow-empty', '-m', 'foo bar')
git ls-tree -r -t HEAD -> output = repo.git.ls_tree('-r', '-t', 'HEAD')