简体   繁体   English

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

[英]howto use gitpython repo.archive() for a tag

I have to export a specific path of a tag. 我必须导出标签的特定路径。 The git command is git archive <tag> but I didn't found a possibility to do this with gitpython git命令是git archive <tag>但是我没有发现可以用gitpython做到这一点

I've tried 我试过了

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

without luck. 没有运气。

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

You can translate almost all git commands to repo.git.<cmd>(arg0, arg1, ...) . 您可以将几乎所有的git命令转换为repo.git.<cmd>(arg0, arg1, ...) Need to replace - in the command name with _ . 需要用_替换-命令名称。

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM