当我使用GitPython尝试以下代码时:
repo.head.commit.diff('HEAD~1')[0].diff它总是返回一个空字符串。我也在不同的提交中尝试过多次更改文件。
我还尝试了下面的代码,它将列出在第一次提交和最后一次提交之间更改的所有文件。
changed_files = []
for x in commits_list[0].diff(commits_list[-1]):
if x.a_blob.path not in changed_files:
changed_files.append(x.a_blob.path)
if x.b_blob is not None and x.b_blob.path not in changed_files:
changed_files.append(x.b_blob.path)
print changed_files发布于 2015-09-02 00:46:09
来自docs (pydoc git.Commit)。
| Methods inherited from git.diff.Diffable:
|
| diff(self, other=<class 'git.diff.Index'>, paths=None, create_patch=False, **kwargs)
[...]
| :param create_patch:
| If True, the returned Diff contains a detailed patch that if applied
| makes the self to other. Patches are somwhat costly as blobs have to be read
| and diffed.因此,如果复制代码,就会得到一个空的diff属性:
>>> import git
>>> r = git.Repo('.')
>>> c1 = r.head.commit
>>> c2 = r.commit('HEAD~1')
>>> print c1.diff(c2)[0].diff但是如果我们将create_patch设置为True
>>> print c1.diff(c2, create_patch=True)[0].diff
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -4593,19 +4593,11 @@ class ComputeManager(manager.Manager):
LOG.debug("Updating volume usage cache with totals",
instance=instance)
[...]https://stackoverflow.com/questions/32342684
复制相似问题