在不使用git命令的情况下,从github存储库中获取更改线

发布于 2025-02-06 07:17:24 字数 899 浏览 2 评论 0原文

我的目标

我正在python中构建一个只能访问历史git diff补丁的Git Stats脚本,因此基本上文件 像这样

diff --git a/README b/README
index 980a0d5f..fef29374 100644
--- a/README
+++ b/README
@@ -1 +1,3 @@
 Hello World!
+
+Hello planet! - DD
\ No newline at end of file

我到底想要什么?

  1. 将git diff文件的列表作为输入
  2. 计算计算更改了多少行(可选),在每个diff文件中添加和删除,
  3. 然后删除它所有的
  4. 打印“添加了总线= x,删除的总线路= y”等。

约束

运行的系统该脚本无法访问GIT存储库,也没有安装GIT-引入有趣的并发症。

通过Python访问API或编写代码以手动计算内容,我没有问题。我唯一的问题是我上面提到的。

存储库托管在GitHub上,允许使用GitHub特定设施。

我检查过的其他来源

,所以我知道有关此主题有许多类似的问题。我只是难以直接在存储库中找到我在Python中寻找的东西...


那么,有什么想法吗?我认为我只能手动解析每个差异文件并总结一下,但是我希望来自git魔术师的银色子弹!

The goal

I am building a git stats script in Python that can only access the historical git diff patches, so basically files like this

diff --git a/README b/README
index 980a0d5f..fef29374 100644
--- a/README
+++ b/README
@@ -1 +1,3 @@
 Hello World!
+
+Hello planet! - DD
\ No newline at end of file

What do I want exactly?

  1. Take a list of git diff files as input
  2. Calculate how many lines were changed (optional), added and removed in each diff file
  3. Sum it all up
  4. Print "total lines added = X, total lines removed = Y" etc.

Constraints

The system running this script does not have access to the git repository, nor does it have git installed - introducing an interesting complication.

I have no issues with accessing the API through Python or writing code to manually calculate things. The only issue I have is what I mentioned above.

The repository is hosted on GitHub, and usage of GitHub-specific facilities is allowed.

Other sources

I checked, and so I know there were many similar questions on this topic. I'm just having trouble finding what I'm looking for in Python, without using git in the repository directly... (happy to close this if someone can point me to a solution)


So then, any ideas? I assume I can just manually parse each of the diff files and sum it up, but I'm hoping for a silver bullet from a git magician!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2025-02-13 07:17:24

事实证明,GitHub API已经提供了这些差异统计数据,而无需安装git在本地检查或存储库。

github docs

由于这对我的情况已经足够好,所以我将使用它。不过,新答案仍然受到欢迎。

It turns out that GitHub API already offers these diff stats without the need to have git installed or repository checked out locally.

GitHub Docs

Since this is good enough for my case, I'm going to use it. New answers are still welcome though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文