我正在尝试访问单个文件的提交历史记录,如下所示:
git log --follow -- <filename>我必须使用gitpython,所以我现在要做的是:
import git
g = git.Git('repo_dir')
hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') 然后我构建提交对象:
repo = git.Repo('repo_dir')
commits = [repo.rev_parse(c) for c in r]有没有一种更像gitpython的方式呢?我尝试过commit.iter_parents()和commit.iter_items(),但它们都依赖于git-rev-list,所以它们没有--follow选项。
发布于 2013-11-19 20:57:45
例如,
使用范围时间:
g = git.Git("C:/path/to/your/repo")
loginfo = g.log('--since=2013-09-01','--author=KIM BASINGER','--pretty=tformat:','--numstat')
print loginfo输出:
3 2 path/in/your/solutions/some_file.cs您可以看到添加的行、删除的行以及具有这些更改的文件。
发布于 2019-02-08 19:07:15
我建议您使用 (它在内部使用GitPython )。更易于使用:
for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
# here you have the commit object
print(commit.hash)https://stackoverflow.com/questions/10073154
复制相似问题