【问题标题】:Get the age of a file in the terms of commits in git根据 git 中的提交条款获取文件的年龄
【发布时间】:2015-12-12 09:40:44
【问题描述】:

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

所以我的想法是这样的:

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

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

【问题讨论】:

  • 不是每个 git 提交都引用了整个文件树吗?您需要区分相邻的提交以确定文件是否更改,
  • 这是真的,但是有例如git show --stat <commitish> 能够列出提交中的文件更改,但它不稳定,并且还包含我不想解析的额外信息出
  • git show 只是对其父级进行提交的差异(如果与多个父级合并,则合并差异)。你必须做同样的事情(也许让 git 为你做这件事,例如,git diff-tree --name-status)来检测变化。
  • 谢谢,但是什么命令会给我一个提交所触及的所有文件的列表(添加、修改、移动或访问或类型更改)

标签: python git


【解决方案1】:

最终的解决方案是使用git diff-tree -z --name-only --no-commit-id -r <sha>

来源:提问者 EdJoJob had edited the question 包含此内容。

【讨论】:

    【解决方案2】:

    git show --stat <commitish> 能够列出提交中的文件更改,但不稳定,

    它可以是稳定的,带有--porcelain 选项:

    使用特殊的基于行的格式用于脚本使用
    添加/删除/未更改的运行以通常的统一差异格式打印,从行首的 +/-/ 字符开始并延伸到行尾。
    输入中的换行符由单独一行的波浪号 ~ 表示。

    你仍然需要做一些解析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 2017-02-18
      • 2016-01-17
      • 1970-01-01
      相关资源
      最近更新 更多