git log --follow,gitpython 方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10073154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git log --follow, the gitpython way
提问by Alberto Bacchelli
I am trying to access the commit history of a single file as in:
我正在尝试访问单个文件的提交历史记录,如下所示:
git log --follow -- <filename>
I have to use gitpython, so what I am doing now is:
我必须使用gitpython,所以我现在正在做的是:
import git
g = git.Git('repo_dir')
hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n')
then I build commit objects:
然后我构建提交对象:
repo = git.Repo('repo_dir')
commits = [repo.rev_parse(c) for c in r]
Is there a way to do it in a more gitpython-ic way?
I tried both commit.iter_parents()
and commit.iter_items()
, but they both rely on git-rev-list
, so they don't have a --follow
option.
有没有办法以更 gitpython-ic 的方式做到这一点?我尝试了commit.iter_parents()
和commit.iter_items()
,但它们都依赖于git-rev-list
,所以他们--follow
别无选择。
回答by mimin0
For example,
例如,
With range time:
随着范围时间:
g = git.Git("C:/path/to/your/repo")
loginfo = g.log('--since=2013-09-01','--author=KIM BASINGER','--pretty=tformat:','--numstat')
print loginfo
Output:
输出:
3 2 path/in/your/solutions/some_file.cs
You can see the added lines, removed lines and the file with these changes.
您可以看到添加的行、删除的行以及具有这些更改的文件。