13

Python スクリプトで、git リポジトリのクローンを作成した後、タグをチェックアウトしようとしました。GitPython 0.3.2 を使用しています。

#!/usr/bin/env python
import git
g = git.Git()
g.clone("user@host:repos")
g = git.Git(repos)
g.execute(["git", "checkout", "tag_name"])

このコードでエラーが発生しました:

g.execute(["git", "checkout", "tag_name"])
File "/usr/lib/python2.6/site-packages/git/cmd.py", line 377, in execute
raise GitCommandError(command, status, stderr_value)
GitCommandError: 'git checkout tag_name' returned exit status 1: error: pathspec 'tag_name' did not match any file(s) known to git.

タグ名をブランチ名に置き換えれば問題ありません。GitPython のドキュメントに情報が見つかりませんでした。シェルで同じタグをチェックアウトしようとしても、問題はありません。

Python で git タグをチェックアウトする方法を知っていますか?

4

3 に答える 3

10

「path/to/repo」でリポジトリをクローンしたと仮定して、これを試してください:

from git import Git

g = Git('path/to/repo')

g.checkout('tag_name')
于 2015-01-08T13:34:23.623 に答える
1
from git import Git
g = Git(repo_path)
g.init()
g.checkout(version_tag)

cmd.py Class Git コメントのように言う

"""
The Git class manages communication with the Git binary.

It provides a convenient interface to calling the Git binary, such as in::

 g = Git( git_dir )
 g.init()                   # calls 'git init' program
 rval = g.ls_files()        # calls 'git ls-files' program

``Debugging``
    Set the GIT_PYTHON_TRACE environment variable print each invocation
    of the command to stdout.
    Set its value to 'full' to see details about the returned values.
""" 
于 2016-12-29T09:51:33.570 に答える