Advertisement
Guest User

prune

a guest
Aug 19th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. function prune() {
  5.    
  6.     local time_spec="1 minute ago"
  7.    
  8.     if ! which git &>/dev/null; then
  9.             echo "Please install a recent version of Git" >&2
  10.             echo "See http://git.or.cz for more information about Git" >&2
  11.             exit 1
  12.         fi
  13.  
  14.     if test $(git rev-parse "HEAD@{$time_spec}") = "$(git rev-parse HEAD)"; then
  15.         echo "You are about to remove *all* commits made before the very last one you made"
  16.         read
  17.     fi
  18.  
  19.     # Something like that
  20.     git filter-branch --parent-filter \
  21.     'test $(git rev-parse "HEAD@{$time_spec}") = "$GIT_COMMIT" || cat ' \
  22.     HEAD
  23.     if test "$?" != "0"; then
  24.         die "Please make sure you did '$SCRIPT_NAME commit' before removing old files."
  25.     fi
  26.  
  27.     # See git mailing list
  28.     # "Trying to use git filter-branch to compress history by removing
  29.     # large, obsolete binary files"
  30.    
  31.     echo "Soft reset and cleanup refs"
  32.     git reset --soft # was '--hard' on the post...
  33.     rm -rf .git/refs/original/
  34.     #vi .git/packed-refs # Use vi to remove the line referring to
  35.     # refs/original...  No need since we have linear, no tags, nothing
  36.     # special
  37.     git reflog expire --all --expire=now --expire-unreachable=0
  38.    
  39.     echo "Repack and prune"
  40.     git repack -ad
  41.     git gc --prune=now
  42.    
  43.     git push origin +master:master
  44.  
  45.     # echo "Committing the removal action"
  46.     # Make sure we are able to tell in a commit that on this
  47.     # date, a cleanup was made
  48.     # local removal_date=$( date +"%a, %d %b %Y %H:%M:%S %z" )
  49.     #   local witness_file=.git-home-history-last-removal
  50.     #   local msg="Removed older than '$time_spec' on $removal_date"
  51.     #   echo "$msg" > ${witness_file}
  52.     #   git add $witness_file
  53.     #   git commit -m "$msg" $witness_file
  54.     #   git push
  55.  
  56. }
  57.  
  58. git pull
  59. prune
  60. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement