现在,我可以使用 pygit2 库遍历 github 存储库的提交树。我正在获取存储库中每个文件更改的所有提交。这意味着我也在存储库中获得扩展名为 .rtf 的文本文件的更改。如何过滤掉仅与代码更改相关的提交?我不想要与文本文档相关的更改。
感谢任何帮助或指示。谢谢。
last = repo[repo.head.target]
t0=last
f = open(outputFile,'w')
print t0.hex
for commit in repo.walk(last.id):
if t0.hex == commit.hex:
continue
print commit.hex
out=repo.diff(t0,commit)
f.write(out.patch)
t0=commit;
作为输出的一部分,我得到了 rtf 文件的差异以及以下内容:
diff --git a/archived-output/NEW/action-core[best].rtf b/archived-output/NEW/action-core[best].rtf
deleted file mode 100644
index 56cdec6..0000000
--- a/archived-output/NEW/action-core[best].rtf
+++ /dev/null
@@ -1,8935 +0,0 @@
-{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
-{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f3\fbidi \froman\fcharset2\fprq2{\*\panose 05050102010706020507}Symbol;}
要么我必须从树中过滤提交,要么我必须过滤输出。我在想是否可以通过在遍历树时删除相应的提交来删除与 rtf 文件相关的更改。