Last active
November 3, 2021 05:34
-
-
Save gizmoguy/d7842180740cffa9c9b8fdb076bce554 to your computer and use it in GitHub Desktop.
Get all locations-of-interest.csv files from git repo
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 | |
# Get all versions of a file in a git repo | |
# Where to output new files | |
output_dir="/tmp/all_loc_csvs" | |
# Which file are we interested in? | |
file_of_interest="locations-of-interest/august-2021/locations-of-interest.csv" | |
mkdir -p "${output_dir}" | |
all_git_blobs=$( | |
git rev-list --objects --all \ | |
| grep ${file_of_interest} \ | |
| cut -d ' ' -f 1 | |
) | |
for blob in ${all_git_blobs}; do | |
out_dirname_blob=$(dirname "${output_dir}/by-blob-id/${blob}/${file_of_interest}") | |
mkdir -p "${out_dirname_blob}" | |
out_filename=$(basename "${file_of_interest}") | |
git cat-file -p "${blob}" > "${out_dirname_blob}/${out_filename}" | |
done | |
all_git_commits=$( | |
git log --format=oneline \ | |
| cut -d ' ' -f 1 | |
) | |
for commit in ${all_git_commits}; do | |
if ! git ls-tree -r "${commit}" | grep "${file_of_interest}" > /dev/null; then | |
continue | |
fi | |
commit_date=$(git show -s --format=%ct "${commit}") | |
out_dirname_commit=$(dirname "${output_dir}/by-commit/${commit}/${file_of_interest}") | |
out_dirname_date=$(dirname "${output_dir}/by-date/${commit_date}/${file_of_interest}") | |
mkdir -p "${out_dirname_commit}" | |
mkdir -p "${out_dirname_date}" | |
out_filename=$(basename "${file_of_interest}") | |
git show "${commit}:${file_of_interest}" > "${out_dirname_commit}/${out_filename}" | |
git show "${commit}:${file_of_interest}" > "${out_dirname_date}/${out_filename}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment