Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function prune() {
- local time_spec="1 minute ago"
- if ! which git &>/dev/null; then
- echo "Please install a recent version of Git" >&2
- echo "See http://git.or.cz for more information about Git" >&2
- exit 1
- fi
- if test $(git rev-parse "HEAD@{$time_spec}") = "$(git rev-parse HEAD)"; then
- echo "You are about to remove *all* commits made before the very last one you made"
- read
- fi
- # Something like that
- git filter-branch --parent-filter \
- 'test $(git rev-parse "HEAD@{$time_spec}") = "$GIT_COMMIT" || cat ' \
- HEAD
- if test "$?" != "0"; then
- die "Please make sure you did '$SCRIPT_NAME commit' before removing old files."
- fi
- # See git mailing list
- # "Trying to use git filter-branch to compress history by removing
- # large, obsolete binary files"
- echo "Soft reset and cleanup refs"
- git reset --soft # was '--hard' on the post...
- rm -rf .git/refs/original/
- #vi .git/packed-refs # Use vi to remove the line referring to
- # refs/original... No need since we have linear, no tags, nothing
- # special
- git reflog expire --all --expire=now --expire-unreachable=0
- echo "Repack and prune"
- git repack -ad
- git gc --prune=now
- git push origin +master:master
- # echo "Committing the removal action"
- # Make sure we are able to tell in a commit that on this
- # date, a cleanup was made
- # local removal_date=$( date +"%a, %d %b %Y %H:%M:%S %z" )
- # local witness_file=.git-home-history-last-removal
- # local msg="Removed older than '$time_spec' on $removal_date"
- # echo "$msg" > ${witness_file}
- # git add $witness_file
- # git commit -m "$msg" $witness_file
- # git push
- }
- git pull
- prune
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement