Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- DATE=""
- # Get the last commit of each month (not the first)
- git log --date=raw --pretty='format:%cd %H' | while read -r time tz hash; do
- CDATE=$(gdate -d @"$time" '+%Y-%m')
- if [ "$DATE" != "$CDATE" ]; then
- echo "$hash" >> ~/Desktop/tmp.txt
- DATE=$CDATE
- fi
- done
- # Rewrite history to squash commits monthly
- git filter-branch -f --commit-filter '
- # Check if the current commit hash is in the tmp file
- if grep -q "$GIT_COMMIT" ~/Desktop/tmp.txt; then
- git commit-tree "$@"
- else
- # Skip the commit but merge its changes into the next kept commit
- skip_commit "$@"
- fi
- ' HEAD
- # Optional: Force push (use with caution)
- # git push --force-with-lease
Advertisement
Add Comment
Please, Sign In to add comment