git的日志--follow的gitpython方式

问题描述 投票:29回答:2

我试图访问一个文件的提交历史,如下所示:

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-IC的方式?我想这两个commit.iter_parents()commit.iter_items(),但他们都依靠git-rev-list,所以他们没有--follow选项。

python git gitpython
2个回答
11
投票

例如,

随着时间范围:

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

你可以看到添加的行,删除的行和这些变化的文件。


3
投票

我建议你改用PyDriller(它使用GitPython内部)。更容易使用:

for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
    # here you have the commit object
    print(commit.hash)
© www.soinside.com 2019 - 2024. All rights reserved.