【问题标题】:How to get last touched lines in a file of a commit: PyDriller?如何获取提交文件中最后触及的行:PyDriller?
【发布时间】:2022-01-10 20:27:25
【问题描述】:

我是 git、API 和 python 的新手。目前我正在使用 PyDriller 并尝试提取提交的修改文件的最后触摸行。 [我的主要目的是我想找出文件的哪个类拥有这些最后触及的行。 ]

for commit in Repository('testing').traverse_commits():
   for modified_file in commit.modified_files:
       print(modified_file.get_commits_last_modified_lines)

但它向我显示了如下错误:

AttributeError: 'ModifiedFile' object has no attribute 'get_commits_last_modified_lines'

“get_commits_last_modified_lines”写在 API PyDriller Reference 中。但我不能使用它。我该怎么办?

【问题讨论】:

标签: python git api github


【解决方案1】:

chapter in Git 表明 Git.get_commits_last_modified_lines 方法正在应用到存储库,并将提交作为参数。

# commit abc modified line 1 of file A
# commit def modified line 2 of file A
# commit ghi modified line 3 of file A
# commit lmn deleted lines 1 and 2 of file A

gr = Git('test-repos/test5')

commit = gr.get_commit('lmn')
buggy_commits = gr.get_commits_last_modified_lines(commit)
print(buggy_commits)      # result: (abc, def)

在你的情况下:

print(gr.get_commits_last_modified_lines(commit, modified_file)

gr 被定义为Repository('testing')

【讨论】:

猜你喜欢
  • 2015-09-20
  • 1970-01-01
  • 2011-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-14
  • 1970-01-01
相关资源
最近更新 更多