python - 根据 git 中的提交获取文件的年龄

标签 python git

我想获得一些关于我的存储库中哪些文件最近处于事件状态的指标,使用存储后不需要任何计算的度量。因此在最后一次修改之前的提交次数。

所以我的想法是:

file_list = subprocess.Popen(['git', 'ls-files'])
(files, _) = proc.communicate()

missing_ages = files
ages = {f: -1 for f in old_ages}

commits_proc = subprocess.Popen(['git', 'ref-list', '--all', '--pretty=format:""'])
(commits, _) = commits_proc.communicate()
age = 0

for commit_sha in [s.split(' ')[1] for s in commits]
    commit_list = subprocess.Popen('some', 'git', 'command')
    commit_files = commit_list.communicate()

    for file in commit_files
        if file in missing_ages
            ages[file] = age
            missing_ages.remove(file)
     age += 1

我需要的是一个 non-porcelain git 命令来获取给定 sha 的提交中的文件列表。

最佳答案

git show --stat <commitish> which is able to list the files changes in a commit, but it is not stable,

它可以稳定,与--porcelain选项:

Use a special line-based format intended for script consumption.
Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/ character at the beginning of the line and extending to the end of the line.
Newlines in the input are represented by a tilde ~ on a line of its own.

不过,您仍然需要进行一些解析。

关于python - 根据 git 中的提交获取文件的年龄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32597811/

相关文章:

git - 无法访问 'git/attributes'

git - 有没有比 Git 更好的数据库(具有可序列化、不可变、版本化的树)?

Python 列表切片效率

python - 如何在 python 中为请求者支付存储桶创建签名的 s3 url

itertools.product 的 python 输入

python - 如何有效地将 Gensim 语料库转换为 numpy 数组(或 scipy 稀疏矩阵)?

git - 删除提交的父级,从而使其成为初始提交

git - Jenkins groovy - 如何从最新提交中检索标签?

git - 在 Windows git pull and clone for Google cloud repository pop 凭据管理器对话框

python - 线性回归模型(使用梯度下降)在波士顿住房数据集上不收敛