repo-flatten-0.2.1 is not a library.
Flatten
A command-line utility to flatten all files from a Git repository into a single text file. This tool is particularly useful for feeding entire codebases into Large Language Models (LLMs) for analysis, documentation, or code review purposes.
Features
- 🔍 Git-aware: Works directly with Git repositories and specific revisions
- 📁 Complete file extraction: Processes all files from any Git commit, branch, or tag
- 🚫 Binary file handling: Automatically detects and skips binary files with placeholders
- 📝 Clear file separation: Each file is clearly marked with headers for easy navigation
- ⚡ Fast and efficient: Uses Git's native object database for optimal performance
- 🛠️ Flexible output: Customizable output file location
Installation
From Source
The binary will be available at target/release/flatten (or target/release/flatten.exe on Windows).
Using Cargo
Usage
Basic Usage
# Flatten the current repository to default output file
# Flatten a specific repository
# Flatten a specific branch or commit
# Specify custom output file
Command Line Options
Options:
-r, --repo <REPO_PATH> The path to the git repository [default: .]
-v, --rev <REVISION> The git revision to inspect (branch, tag, or commit hash) [default: HEAD]
-o, --output <OUTPUT_FILE> The path for the output file [default: flattened_files.txt]
-h, --help Print help
-V, --version Print version
Examples
# Flatten the main branch of a repository
# Flatten a specific commit
# Flatten current repository with custom output
Output Format
The tool creates a text file with the following structure:
[file content here]
[file content here]
[Binary file: content not included]
Use Cases
- LLM Analysis: Feed entire codebases to language models for code review, documentation generation, or refactoring suggestions
- Code Documentation: Create comprehensive snapshots of project states
- Legacy Code Analysis: Extract and analyze historical versions of codebases
- Code Migration: Prepare code for migration tools that require flat file inputs
- Educational Purposes: Create teaching materials from real-world codebases
Technical Details
- Language: Rust 2024 Edition
- Dependencies:
clap- Command-line argument parsinggit2- Git repository accessanyhow- Error handling
- Binary Detection: Automatically identifies binary files and excludes their content
- Memory Efficient: Streams file content directly to output without loading entire repository into memory
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Author
Irving Ou - jou@devolutions.net
Note: This tool respects Git's ignore rules by default and will only process files that are tracked in the Git repository at the specified revision.