可以使用git命令行工具结合一些脚本来实现。下面是一个可能的解决方案:
git log --pretty=format:"%h,%an,%ad"
命令获取所有提交的历史记录。该命令会返回每个提交的短哈希值、作者名和提交日期。git ls-tree -r --name-only HEAD
命令获取当前分支下的所有文件列表。该命令会返回每个文件的相对路径。git log --follow --oneline -- <file>
命令获取该文件的提交历史。该命令会返回该文件的每个提交的简短信息。下面是一个示例Python脚本,用于获取每个目录的git提交统计信息:
import subprocess
import os
def get_commit_stats():
commit_stats = {}
# 获取所有提交的历史记录
log_output = subprocess.check_output(['git', 'log', '--pretty=format:%h,%an,%ad'])
commits = log_output.decode().split('\n')
# 获取当前分支下的所有文件列表
file_output = subprocess.check_output(['git', 'ls-tree', '-r', '--name-only', 'HEAD'])
files = file_output.decode().split('\n')
# 遍历文件列表,获取每个文件的提交历史
for file in files:
if file:
# 获取文件的提交历史
file_log_output = subprocess.check_output(['git', 'log', '--follow', '--oneline', '--', file])
file_commits = file_log_output.decode().split('\n')
# 解析每个提交的信息
for commit in file_commits:
if commit:
commit_info = commit.split(',')
commit_hash = commit_info[0]
commit_author = commit_info[1]
commit_date = commit_info[2]
# 获取目录路径
directory = os.path.dirname(file)
# 统计每个目录的提交次数
if directory in commit_stats:
commit_stats[directory] += 1
else:
commit_stats[directory] = 1
return commit_stats
# 测试
stats = get_commit_stats()
for directory, count in stats.items():
print(f"目录: {directory},提交次数: {count}")
这个脚本会输出每个目录的提交次数。你可以根据需要进一步扩展脚本,添加更多的统计信息或输出格式。
对于腾讯云相关产品,可以根据具体需求选择适合的产品。例如,如果需要存储和管理代码仓库,可以使用腾讯云的CodeCommit(https://cloud.tencent.com/product/ccr);如果需要构建和部署应用程序,可以使用腾讯云的Serverless Framework(https://cloud.tencent.com/product/sls)等。请根据具体场景和需求选择适合的产品。
领取专属 10元无门槛券
手把手带您无忧上云