Last active
June 18, 2024 00:15
-
-
Save robert-cronin/02215e61893d6616fc0d269e829b50ed to your computer and use it in GitHub Desktop.
A script for concatenating all the files of a git repo into one file which you can feed into large context LLMs for understanding dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the script received the correct number of arguments | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <repo_path> <output_file>" | |
exit 1 | |
fi | |
REPO_PATH=$1 | |
OUTPUT_FILE=$2 | |
# Change to the repository directory | |
cd "$REPO_PATH" || { | |
echo "Repository path not found" | |
exit 1 | |
} | |
# Ensure the output file is empty | |
true >"$OUTPUT_FILE" | |
# Use git ls-files to get all tracked and not ignored files | |
git ls-files | while IFS= read -r file; do | |
# Print the relative path of the file | |
echo "\`\`\`repo/$file" >>"$OUTPUT_FILE" | |
# Print the file content | |
cat "$file" >>"$OUTPUT_FILE" | |
# Add a new line to separate files | |
echo "" >>"$OUTPUT_FILE" | |
echo "\`\`\`" >>"$OUTPUT_FILE" | |
done | |
echo "All tracked and not ignored files in the repository have been concatenated into $OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment