提取已修改文件的路径,删除或重命名的文件除外
Extract paths to modified files except for deleted or renamed files
我需要使用 GitPython 获取在上次提交中更改的文件的路径。
我设法这样做了:
import os
from git import Repo
repo = Repo(os.path.dirname(sys.argv[0]))
commit = list(repo.iter_commits(max_count=1))[0]
files = commit.stats.files
for filepath in files:
print(filepath)
但现在我想过滤掉那些被删除或重命名的文件,我有点受不了了。如果有任何帮助,我将不胜感激,也许有人有这样的经历。
previous_commit = repo.commit('HEAD~1')
# Deleted
for diff_del in previous_commit.diff('HEAD').iter_change_type('D'):
print(diff_del.a_path)
# Renamed
for diff_mv in previous_commit.diff('HEAD').iter_change_type('R'):
print(diff_mv.a_path)
# Modified
for diff_mod in previous_commit.diff('HEAD').iter_change_type('M'):
print(diff_mod.a_path)
我需要使用 GitPython 获取在上次提交中更改的文件的路径。 我设法这样做了:
import os
from git import Repo
repo = Repo(os.path.dirname(sys.argv[0]))
commit = list(repo.iter_commits(max_count=1))[0]
files = commit.stats.files
for filepath in files:
print(filepath)
但现在我想过滤掉那些被删除或重命名的文件,我有点受不了了。如果有任何帮助,我将不胜感激,也许有人有这样的经历。
previous_commit = repo.commit('HEAD~1')
# Deleted
for diff_del in previous_commit.diff('HEAD').iter_change_type('D'):
print(diff_del.a_path)
# Renamed
for diff_mv in previous_commit.diff('HEAD').iter_change_type('R'):
print(diff_mv.a_path)
# Modified
for diff_mod in previous_commit.diff('HEAD').iter_change_type('M'):
print(diff_mod.a_path)