我想获得一些关于我的存储库中哪些文件最近处于事件状态的指标,使用存储后不需要任何计算的度量。因此在最后一次修改之前的提交次数。
所以我的想法是:
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/