Skip to content

Instantly share code, notes, and snippets.

@umjammer
Last active January 3, 2016 05:48
Show Gist options
  • Save umjammer/8417994 to your computer and use it in GitHub Desktop.
Save umjammer/8417994 to your computer and use it in GitHub Desktop.
removing over 100MB files

get commit ids.

$ git log | grep commit | awk '{print $2}' | tac > commits.txt

find files which has over size 100MB

$ cat commits.txt | while read i ; do git ls-tree -r -l $i ; done | awk '{if ($4 > 100 * 1024 * 1024) print $5, $4}'

remove from commits.

$ git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch $FILE' --prune-empty --tag-name-filter cat -- --all
$ git commit --amend -CHEAD

if github says

 error: unable to push to unqualified destination: master
 The destination refspec neither matches an existing ref on the remote nor
 begins with refs/, and we are unable to guess a prefix based on the source ref.
 error: failed to push some refs to 'https://github.com/foo/bar.git'
(because of github refused for too big size pushing)
and, you've never commit to the remote github repository.
$ git clone original_repository temp
$ cd temp
$ git reset --soft commit_id_you_want_to_rewind                     # means first commit for minimize amount of size to push
$ git push origin master
$ cd $original_repository
$ git log | grep commit | awk '{print $2}' | tac > commits.txt
$ vi commits.txt                                                    # remove commit ids which you've already pushed. 
$ cat commits.txt | while read i ; do git push -u origin $i:master ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment