Alb*_*lli 33 python git gitpython
我试图访问单个文件的提交历史记录,如下所示:
git log --follow -- <filename>
Run Code Online (Sandbox Code Playgroud)
我必须使用gitpython,所以我现在正在做的是:
import git
g = git.Git('repo_dir')
hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n')
Run Code Online (Sandbox Code Playgroud)
然后我构建提交对象:
repo = git.Repo('repo_dir')
commits = [repo.rev_parse(c) for c in r]
Run Code Online (Sandbox Code Playgroud)
有没有办法以更加gitpython-ic的方式做到这一点?我都尝试commit.iter_parents()和commit.iter_items(),但他们都依靠git-rev-list,所以他们没有--follow选择.
小智 11
例如,
有了范围时间:
g = git.Git("C:/path/to/your/repo")
loginfo = g.log('--since=2013-09-01','--author=KIM BASINGER','--pretty=tformat:','--numstat')
print loginfo
Run Code Online (Sandbox Code Playgroud)
输出:
3 2 path/in/your/solutions/some_file.cs
Run Code Online (Sandbox Code Playgroud)
您可以通过这些更改查看添加的行,删除的行和文件.
小智 7
我建议您改用PyDriller(它在内部使用 GitPython)。更容易使用:
for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
# here you have the commit object
print(commit.hash)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13430 次 |
| 最近记录: |