Skip to content

Instantly share code, notes, and snippets.

@rudolfolah
Created July 21, 2024 12:08
Show Gist options
  • Save rudolfolah/ecc4b6f84754b449f1e97afab3ed054c to your computer and use it in GitHub Desktop.
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.
#!/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