usage.md•4.59 kB
# 基本用法
## 快速开始
打包整个仓库:
```bash
repomix
```
## 常见使用场景
### 打包指定目录
```bash
repomix path/to/directory
```
### 包含特定文件
使用 [glob 模式](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax):
```bash
repomix --include "src/**/*.ts,**/*.md"
```
### 排除文件
```bash
repomix --ignore "**/*.log,tmp/"
```
### 处理远程仓库
```bash
# 使用 GitHub URL
repomix --remote https://github.com/user/repo
# 使用简写形式
repomix --remote user/repo
# 指定分支/标签/提交
repomix --remote user/repo --remote-branch main
repomix --remote user/repo --remote-branch 935b695
```
### 文件列表输入(stdin)
通过 stdin 传递文件路径以获得终极灵活性:
```bash
# 使用 find 命令
find src -name "*.ts" -type f | repomix --stdin
# 使用 git 获取跟踪的文件
git ls-files "*.ts" | repomix --stdin
# 使用 ripgrep (rg) 查找文件
rg --files --type ts | repomix --stdin
# 使用 grep 查找包含特定内容的文件
grep -l "TODO" **/*.ts | repomix --stdin
# 使用 ripgrep 查找包含特定内容的文件
rg -l "TODO|FIXME" --type ts | repomix --stdin
# 使用 sharkdp/fd 查找文件
fd -e ts | repomix --stdin
# 使用 fzf 从所有文件中选择
fzf -m | repomix --stdin
# 使用 fzf 进行交互式文件选择
find . -name "*.ts" -type f | fzf -m | repomix --stdin
# 使用 ls 和 glob 模式
ls src/**/*.ts | repomix --stdin
# 从包含文件路径的文件中读取
cat file-list.txt | repomix --stdin
# 使用 echo 直接输入
echo -e "src/index.ts\nsrc/utils.ts" | repomix --stdin
```
`--stdin` 选项允许您向 Repomix 传递文件路径列表,在选择要打包的文件时提供终极灵活性。
使用 `--stdin` 时,指定的文件实际上被添加到包含模式中。这意味着正常的包含和忽略行为仍然适用 - 通过 stdin 指定的文件如果匹配忽略模式仍会被排除。
> [!NOTE]
> 使用 `--stdin` 时,文件路径可以是相对路径或绝对路径,Repomix 会自动处理路径解析和去重。
### 代码压缩
```bash
repomix --compress
# 您也可以将其用于远程仓库:
repomix --remote yamadashy/repomix --compress
```
### Git 集成
包含Git信息为AI分析提供开发上下文:
```bash
# 包含git差异(未提交的更改)
repomix --include-diffs
# 包含git提交日志(默认最近50个提交)
repomix --include-logs
# 包含特定数量的提交
repomix --include-logs --include-logs-count 10
# 同时包含差异和日志
repomix --include-diffs --include-logs
```
这增加了宝贵的上下文信息:
- **最近更改**:Git差异显示未提交的修改
- **开发模式**:Git日志揭示通常一起更改的文件
- **提交历史**:最近的提交消息提供开发重点的洞察
- **文件关系**:理解在同一提交中修改的文件
### 令牌数量优化
了解代码库的令牌分布对于优化AI交互至关重要。使用 `--token-count-tree` 选项可视化整个项目的令牌使用情况:
```bash
repomix --token-count-tree
```
这将显示带有令牌计数的代码库层次结构视图:
```
🔢 Token Count Tree:
────────────────────
└── src/ (70,925 tokens)
├── cli/ (12,714 tokens)
│ ├── actions/ (7,546 tokens)
│ └── reporters/ (990 tokens)
└── core/ (41,600 tokens)
├── file/ (10,098 tokens)
└── output/ (5,808 tokens)
```
您还可以设置最小令牌阈值来关注较大的文件:
```bash
repomix --token-count-tree 1000 # 仅显示拥有1000+令牌的文件/目录
```
这有助于您:
- **识别重令牌文件** - 可能超出AI上下文限制的文件
- **优化文件选择** - 使用 `--include` 和 `--ignore` 模式
- **规划压缩策略** - 针对最大贡献者的策略
- **平衡内容与上下文** - 为AI分析准备代码时的平衡
## 输出格式
### XML(默认)
```bash
repomix --style xml
```
### Markdown
```bash
repomix --style markdown
```
### JSON
```bash
repomix --style json
```
### 纯文本
```bash
repomix --style plain
```
## 其他选项
### 移除注释
```bash
repomix --remove-comments
```
### 显示行号
```bash
repomix --output-show-line-numbers
```
### 复制到剪贴板
```bash
repomix --copy
```
### 禁用安全检查
```bash
repomix --no-security-check
```
## 配置
初始化配置文件:
```bash
repomix --init
```
更多详细配置选项请参阅[配置指南](/zh-cn/guide/configuration)。