Gitingest
将任意 Git 代码库转换为适合大语言模型(LLM)处理的文本输入。
您也可以将 GitHub URL 中的 hub
替换为 ingest
来获取对应的代码摘要。
gitingest.com · Chrome 扩展 · Firefox 插件
Deutsch | Español | Français | 日本語 | 한국어 | Português | Русский | 中文
🚀 功能特性
- 便捷代码上下文:通过 Git 仓库 URL 或目录获取文本摘要
- 智能格式化:针对 LLM 提示优化的输出格式
- 统计信息:
- 文件与目录结构
- 提取内容大小
- Token 数量统计
- 命令行工具:可作为 shell 命令运行
- Python 包:可在代码中直接导入使用
📚 系统要求
- Python 3.8+
- 私有仓库支持:需要 GitHub 个人访问令牌(PAT)。点击此处生成令牌
📦 安装指南
Gitingest 已发布至 PyPI。 可通过 pip
安装:
pip install gitingest
或
pip install gitingest[server]
包含自托管所需的服务器依赖项。
建议使用 pipx
进行安装,可通过您惯用的包管理器安装 pipx
。
brew install pipx apt install pipx scoop install pipx ...
首次使用 pipx 时需执行:
pipx ensurepath
# install gitingest pipx install gitingest
🧩 浏览器扩展使用
本扩展已在 lcandy2/gitingest-extension 开源。
欢迎在代码仓库提交问题反馈和功能请求。
💡 命令行使用指南
gitingest
命令行工具可帮助您分析代码库并生成内容文本摘要。
# Basic usage (writes to digest.txt by default) gitingest /path/to/directory # From URL gitingest https://github.com/coderamp-labs/gitingest # or from specific subdirectory gitingest https://github.com/coderamp-labs/gitingest/tree/main/src/gitingest/utils
对于私有仓库,请使用 --token/-t
参数。
# Get your token from https://github.com/settings/personal-access-tokens gitingest https://github.com/username/private-repo --token github_pat_... # Or set it as an environment variable export GITHUB_TOKEN=github_pat_... gitingest https://github.com/username/private-repo # Include repository submodules gitingest https://github.com/username/repo-with-submodules --include-submodules
默认会跳过 .gitignore
中列出的文件。若需包含这些文件,请使用 --include-gitignored
参数。
默认情况下,摘要会输出到当前工作目录的 digest.txt
文件。您可以通过两种方式自定义输出:
- 使用
--output/-o <文件名>
指定输出文件 - 使用
--output/-o -
直接输出到标准输出(便于管道操作)
查看完整选项和使用说明:
gitingest --help
🐍 Python 包使用指南
# Synchronous usage from gitingest import ingest summary, tree, content = ingest("path/to/directory") # or from URL summary, tree, content = ingest("https://github.com/coderamp-labs/gitingest") # or from a specific subdirectory summary, tree, content = ingest("https://github.com/coderamp-labs/gitingest/tree/main/src/gitingest/utils")
对于私有仓库,可传入 token 参数:
# Using token parameter summary, tree, content = ingest("https://github.com/username/private-repo", token="github_pat_...") # Or set it as an environment variable import os os.environ["GITHUB_TOKEN"] = "github_pat_..." summary, tree, content = ingest("https://github.com/username/private-repo") # Include repository submodules summary, tree, content = ingest("https://github.com/username/repo-with-submodules", include_submodules=True)
默认不会生成文件,但可通过 output
参数启用。
# Asynchronous usage from gitingest import ingest_async import asyncio result = asyncio.run(ingest_async("path/to/directory"))
Jupyter notebook 使用说明
from gitingest import ingest_async # Use await directly in Jupyter summary, tree, content = await ingest_async("path/to/directory")
这是因为 Jupyter notebook 默认采用异步执行模式。
🐳 自托管指南
Docker方式部署
-
构建镜像:
docker build -t gitingest .
-
运行容器:
docker run -d --name gitingest -p 8000:8000 gitingest
应用将运行在 http://localhost:8000
。
若需部署在域名下,可通过环境变量 ALLOWED_HOSTS
指定允许的主机名。
# Default: "gitingest.com, *.gitingest.com, localhost, 127.0.0.1". ALLOWED_HOSTS="example.com, localhost, 127.0.0.1"
环境变量
可通过以下环境变量配置应用程序:
- ALLOWED_HOSTS: 允许访问的主机名列表(以逗号分隔,默认值:"gitingest.com, *.gitingest.com, localhost, 127.0.0.1")
- GITINGEST_METRICS_ENABLED: 启用 Prometheus 指标服务器(设置任意值即可启用)
- GITINGEST_METRICS_HOST: 指标服务器监听主机(默认值:"127.0.0.1")
- GITINGEST_METRICS_PORT: 指标服务器监听端口(默认值:"9090")
- GITINGEST_SENTRY_ENABLED: 启用 Sentry 错误追踪(设置任意值即可启用)
- GITINGEST_SENTRY_DSN: Sentry DSN(启用 Sentry 时必须配置)
- GITINGEST_SENTRY_TRACES_SAMPLE_RATE: 性能数据采样率(默认值:"1.0",范围:0.0-1.0)
- GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE: 分析会话采样率(默认值:"1.0",范围:0.0-1.0)
- GITINGEST_SENTRY_PROFILE_LIFECYCLE: 分析生命周期模式(默认值:"trace")
- GITINGEST_SENTRY_SEND_DEFAULT_PII: 发送默认个人身份信息(默认值:"true")
- S3_ALIAS_HOST: 访问 S3 资源的公开 URL/CDN(默认值:"127.0.0.1:9000/gitingest-bucket")
- S3_DIRECTORY_PREFIX: S3 文件路径可选前缀(若设置,所有 S3 路径将添加此前缀)
Docker Compose方式部署
项目包含一个 compose.yml
文件,可帮助您轻松在开发和生产环境中运行应用。
Compose 文件结构
compose.yml
文件通过 YAML 锚点 &app-base
和 <<: *app-base
来定义服务间共享的通用配置:
# Common base configuration for all services x-app-base: &app-base build: context: . dockerfile: Dockerfile ports: - "${APP_WEB_BIND:-8000}:8000" # Main application port - "${GITINGEST_METRICS_HOST:-127.0.0.1}:${GITINGEST_METRICS_PORT:-9090}:9090" # Metrics port # ... other common configurations
服务
该文件定义了三个服务:
-
app: 生产环境服务配置
- 使用
prod
配置文件 - 设置 Sentry 环境为 "production"
- 配置为稳定运行模式 (
restart: unless-stopped
)
- 使用
-
app-dev: 开发环境服务配置
- 使用
dev
配置文件 - 启用调试模式
- 挂载源代码实现实时开发
- 使用热重载加速开发流程
- 使用
-
minio: 开发用 S3 兼容对象存储
- 使用
dev
配置文件 (仅开发模式可用) - 为本地开发提供 S3 兼容存储
- 访问方式:
- API: 端口 9000 (localhost:9000)
- Web 控制台: 端口 9001 (localhost:9001)
- 默认管理员凭证:
- 用户名:
minioadmin
- 密码:
minioadmin
- 用户名:
- 可通过环境变量配置:
MINIO_ROOT_USER
: 自定义管理员用户名 (默认: minioadmin)MINIO_ROOT_PASSWORD
: 自定义管理员密码 (默认: minioadmin)
- 通过 Docker 卷提供持久化存储
- 自动创建存储桶和应用专用凭证:
- 存储桶名称:
gitingest-bucket
(可通过S3_BUCKET_NAME
配置) - 访问密钥:
gitingest
(可通过S3_ACCESS_KEY
配置) - 密钥:
gitingest123
(可通过S3_SECRET_KEY
配置)
- 存储桶名称:
- 这些凭证通过环境变量自动传递给 app-dev 服务:
S3_ENDPOINT
: MinIO 服务器 URLS3_ACCESS_KEY
: S3 存储桶访问密钥S3_SECRET_KEY
: S3 存储桶密钥S3_BUCKET_NAME
: S3 存储桶名称S3_REGION
: S3 存储桶区域 (默认: us-east-1)S3_ALIAS_HOST
: 访问 S3 资源的公共 URL/CDN (默认: "127.0.0.1:9000/gitingest-bucket")
- 使用
使用示例
以开发模式运行应用程序:
docker compose --profile dev up
以生产模式运行应用程序:
docker compose --profile prod up -d
构建并运行应用程序:
docker compose --profile prod build docker compose --profile prod up -d
🤝 参与贡献
非技术性贡献方式
- 提交问题:如果您发现错误或有新功能的想法,请在 GitHub 上创建问题。这将帮助我们跟踪并优先处理您的请求。
- 分享传播:如果您喜欢 Gitingest,请与您的朋友、同事分享或在社交媒体上传播。这将帮助我们扩大社区,使 Gitingest 变得更好。
- 使用 Gitingest:最真实的反馈来自实际使用!如果您遇到任何问题或有改进的想法,请通过 GitHub 创建问题 或在 Discord 上联系我们告知我们。
技术性贡献方式
Gitingest 采用简洁的 Python 和 HTML 代码库,特别适合首次贡献者。开发过程中如需帮助,可通过 Discord 联系我们。提交 PR 的详细指南请参阅 CONTRIBUTING.md。
🛠️ 技术栈
- Tailwind CSS - 前端
- FastAPI - 后端框架
- Jinja2 - HTML 模板
- tiktoken - 令牌估算
- posthog - 出色的分析工具
- Sentry - 错误跟踪和性能监控
需要 JavaScript/FileSystemNode 包?
推荐使用 NPM 替代方案 📦 Repomix:https://github.com/yamadashy/repomix