我有一个包含数千个文件的Git存储库,并且想获取每个文件的最后一次提交的日期和时间。可以使用Python完成此操作(例如,使用os.path.getmtime(path))吗?
使用GitPython,这将完成这项工作:
import git
repo = git.Repo("./repo")
tree = repo.tree()
for blob in tree:
commit = repo.iter_commits(paths=blob.path, max_count=1).next()
print(blob.path, commit.committed_date)
Run Code Online (Sandbox Code Playgroud)
请注意,这commit.committed_date是“自纪元以来的秒数”格式。
| 归档时间: |
|
| 查看次数: |
4224 次 |
| 最近记录: |