Created
July 21, 2024 12:08
-
-
Save rudolfolah/ecc4b6f84754b449f1e97afab3ed054c to your computer and use it in GitHub Desktop.
ZSH script that will group files into git commits by modified date. Useful for older repos.
This file contains hidden or 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/zsh | |
format_date() { | |
date -r $1 +"%Y-%m-%dT%H:%M:%S" | |
} | |
declare -A files_by_date | |
git ls-files --modified --others --exclude-standard | while read file | |
do | |
timestamp=$(stat -f "%m" "$file") | |
date=$(format_date $timestamp) | |
files_by_date[$date]+="$file " | |
done | |
for date in "${(k)files_by_date[@]}"; do | |
echo $date "$files_by_date[$date]" | |
echo "$files_by_date[$date]" | xargs git add | |
GIT_AUTHOR_DATE="$date" GIT_COMMITTER_DATE="$date" git commit -m "Updated" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment