【问题标题】:git log --follow, the gitpython waygit log --follow,gitpython方式
【发布时间】:2012-04-09 12:27:07
【问题描述】:

我正在尝试访问单个文件的提交历史,如下所示:

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 选项。

【问题讨论】:

  • 什么是rrepo?

标签: python git gitpython


【解决方案1】:

例如,

有范围时间:

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

您可以看到添加的行、删除的行以及具有这些更改的文件。

【讨论】:

    【解决方案2】:

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

    for commit in RepositoryMining("path_to_repo", filepath="here_the_file").traverse_commits():
        # here you have the commit object
        print(commit.hash)
    

    【讨论】:

      猜你喜欢
      • 2018-03-11
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多