1

感谢您支持我过去几周一直在使用的这个很棒的模块(GitPython)。

我试图在文档中找到 GitPython 中如何调用“git show”的等价物

git show <hexsha>:<directory>/<file>

即使直接与 git 交互

git_ = irepo.git

鉴于已知 hexsha、目录、文件,您能否告诉我如何管理和进行上述“git show”调用?

4

1 回答 1

2

由于 GitPython 不包装show子命令,因此确实必须直接使用 git 命令包装器。

调用git show <hexsha>:<directory>/<file>在 git-python 中看起来像这样。

import git
r = git.Repo(path_to_repo)
res = r.git.show("%s:%s" % (hexsha, file_path))

res将是一个包含由 生成的输出的字符串git show,您必须自己解析它。

更多关于如何直接使用 git 的信息可以在官方文档中找到。

于 2015-02-24T13:07:27.187 回答