Last active
November 19, 2023 16:50
-
-
Save shawntabrizi/d7d7c886b8fead307c735a3802458014 to your computer and use it in GitHub Desktop.
Export each historical commit of a repo into a separate folder.
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 | |
# Name of the folder where files will be copied for each commit | |
output_folder="commit_files" | |
# Create the output folder if it doesn't exist | |
mkdir -p $output_folder | |
# Counter for incrementing folder names | |
counter=1 | |
# Iterate through each commit in the Git history | |
git log --reverse --format="%H" | while read commit_hash; do | |
# Create a folder for each commit | |
commit_folder="$output_folder/$counter" | |
mkdir -p $commit_folder | |
# Checkout the files of the commit into the corresponding folder | |
git clone . $commit_folder | |
# jump into our commit folder | |
pushd $commit_folder | |
# Reset the working directory to the original state | |
git checkout $commit_hash | |
# Remove git from the directory, treating the files as plain | |
rm -rf .git | |
# Go back to our main directory | |
popd | |
# Increment the counter for the next folder | |
((counter++)) | |
done | |
echo "Files copied for each commit in the commit history." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment