作为一个个人项目,我想检查不同的 python 库和项目(无论是专有的还是开源的)并分析代码在不同版本中如何随着时间的推移而变化,以收集有关技术债务的一些信息(主要通过静态代码分析)。我正在使用 gitpython 库来执行此操作。但是,我正在努力过滤对 master
的 merge 提交。
我使用 git.log("--merges", "--first-parent", "master")
过滤 merge 提交,从中提取提交哈希值并过滤这些特定提交来自所有存储库提交。
作为第二部分,我想在每次 merge 提交中获取所有更改的文件。我可以通过 git 树访问 blob,但我不知道如何仅获取已更改的文件。
有什么有效的方法可以实现这一点吗?谢谢!
最佳答案
... I'd like to get all changed files in each merge commit. ... but I don't know how to get only changed files.
一旦你有了上面描述的提交列表,循环它们并运行以下命令:
git diff
将 git diff
与 --name-only
标志一起使用
git diff
--name-only
Show only names of changed files.
--name-status
Show only the names and status of changed files. See the description of the --diff-filter option on what the status letters mean.
关于python - Git:随着时间的推移,获取发布到 master 的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53234954/