Gitingest能把任意Git代码库转换成适合大语言模型(LLM)提示的文本摘要。
你可以直接在网站上输入Git仓库URL,比如输入类似https://github.com/...
的地址后点击“Ingest”按钮,支持设置排除文件,默认排除*.md
、src/
,能设置包含文件的大小限制(默认50kB),以及处理私有仓库(需要GitHub个人访问令牌)。
• 便捷代码上下文:通过Git仓库URL或本地目录获取文本摘要
• 智能格式化:输出格式针对LLM提示进行了优化
• 统计信息:包含文件与目录结构、摘要内容大小、令牌数量统计
• 命令行工具:可以作为shell命令运行
• Python包:能在代码中直接导入使用
• Python 3.8+
• 私有仓库支持:需要GitHub个人访问令牌(PAT),可点击相关链接生成令牌
Gitingest已发布至PyPI,可通过pip
安装:
pip install gitingest
建议使用pipx
进行安装,可通过熟悉的包管理器安装pipx
:
brew install pipx
apt install pipx
scoop install pipx
...
首次使用pipx时需要运行:
pipx ensurepath
# install gitingest
pipx install gitingest
• Chrome浏览器:可在Chrome Web Store获取
• Edge浏览器:可在Edge Add-ons获取
• Firefox浏览器:有对应的Firefox插件
扩展程序开源地址为lcandy2/gitingest-extension
,欢迎在该仓库提交问题与功能请求。
gitingest
命令行工具可以分析代码库并生成内容摘要。
# 基本用法(默认写入digest.txt)
gitingest /path/to/directory
# 从URL获取
gitingest https://github.com/cyclotruc/gitingest
# 从特定子目录获取
gitingest https://github.com/cyclotruc/gitingest/tree/main/src/gitingest/utils
对于私有仓库,使用--token/-t
参数:
# 从https://github.com/settings/personal-access-tokens获取令牌
gitingest https://github.com/username/private-repo --token github_pat_...
# 也可以将令牌设为环境变量
export GITHUB_TOKEN=github_pat_...
gitingest https://github.com/username/private-repo
默认会跳过.gitignore
中列出的文件,若要包含这些文件,使用--include-gitignored
参数。
默认情况下,摘要会输出到当前工作目录的digest.txt
文件。有两种方式自定义输出:
• 使用--output/-o <文件名>
指定输出文件
• 使用--output/-o -
直接输出到标准输出(适用于管道操作)
查看完整选项与使用说明,可运行:
gitingest --help
# 同步使用
from gitingest import ingest
summary, tree, content = ingest("path/to/directory")
# 从URL获取
summary, tree, content = ingest("https://github.com/cyclotruc/gitingest")
# 从特定子目录获取
summary, tree, content = ingest("https://github.com/cyclotruc/gitingest/tree/main/src/gitingest/utils")
对于私有仓库,可传入token参数:
# 使用token参数
summary, tree, content = ingest("https://github.com/username/private-repo", token="github_pat_...")
# 也可设为环境变量
import os
os.environ["GITHUB_TOKEN"] = "github_pat_..."
summary, tree, content = ingest("https://github.com/username/private-repo")
默认不写入文件,可通过output
参数启用:
# 异步使用
from gitingest import ingest_async
import asyncio
result = asyncio.run(ingest_async("path/to/directory"))
from gitingest import ingest_async
# 在Jupyter中直接使用await
summary, tree, content = await ingest_async("path/to/directory")
这是因为Jupyter notebook默认采用异步模式。
构建镜像:
docker build -t gitingest .
运行容器:
docker run -d --name gitingest -p 8000:8000 gitingest
应用将运行在http://localhost:8000
。如需绑定域名,可通过环境变量ALLOWED_HOSTS
指定允许的主机名,默认值为"gitingest.com, *.gitingest.com, localhost, 127.0.0.1"
。