{"id":690,"date":"2014-04-08T11:00:46","date_gmt":"2014-04-08T15:00:46","guid":{"rendered":"https:\/\/reviewsignal.com\/blog\/?p=690"},"modified":"2014-04-06T04:21:59","modified_gmt":"2014-04-06T08:21:59","slug":"how-to-remove-files-from-git-repo-permanently","status":"publish","type":"post","link":"https:\/\/reviewsignal.com\/blog\/2014\/04\/08\/how-to-remove-files-from-git-repo-permanently\/","title":{"rendered":"How To Remove Files from Git Repo Permanently"},"content":{"rendered":"<p>I ran into this issue in the past week. My .PACK file was enormous (many many gigabytes) because I committed a lot of files I shouldn't have in the past. Large binary files, backups and other things that don't belong in a Git repo.<\/p>\n<p>I deleted the files and committed those, but Git is really good at making sure you never lose data. So despite having a small repo, I had a .PACK file that was 10 times the size of the repo.<\/p>\n<p>I googled around a lot and the best post I could find on StackOverflow was <a href=\"http:\/\/stackoverflow.com\/questions\/5563564\/completely-remove-files-from-git-repo-and-remote-on-github\">completely remove files from git repo and github on remote<\/a>. It didn't quite work for me though.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #c20cb9; font-weight: bold;\">git filter-branch<\/span> <span style=\"color: #660033;\">-f<\/span> <span style=\"color: #660033;\">--index-filter<\/span> <span style=\"color: #ff0000;\">'git rm -r --cached --ignore-unmatch &quot;filename&quot;'<\/span> <span style=\"color: #660033;\">--prune-empty<\/span> HEAD\n<span style=\"color: #c20cb9; font-weight: bold;\">rm<\/span> <span style=\"color: #660033;\">-rf<\/span> .git<span style=\"color: #000000; font-weight: bold;\">\/<\/span>refs<span style=\"color: #000000; font-weight: bold;\">\/<\/span>original<span style=\"color: #000000; font-weight: bold;\">\/<\/span> <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">git reflog<\/span> expire <span style=\"color: #660033;\">--expire<\/span>=now <span style=\"color: #660033;\">--all<\/span> <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">git gc<\/span> <span style=\"color: #660033;\">--aggressive<\/span> <span style=\"color: #660033;\">--prune<\/span>=now<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>I just had to add a few flags to get this working.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #660033;\">-f<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p> and<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #660033;\">--prune-empty<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p> in the git filter-branch.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #660033;\">--expire<\/span>=now<\/pre><\/td><\/tr><\/table><\/div>\n\n<p> and<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #660033;\">--prune<\/span>=now<\/pre><\/td><\/tr><\/table><\/div>\n\n<p> in the second line of commands.<\/p>\n<p>Now you can run those two commands (replacing filename with a file name or directory) and it should permanently remove the file from the repo including the PACK file. <\/p>\n<p>Be very careful when you run this command, I am not sure there is a way to undo this change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into this issue in the past week. My .PACK file was enormous (many many gigabytes) because I committed a lot of files I shouldn&#8217;t have in the past. Large binary files, backups and other things that don&#8217;t belong in a Git repo. I deleted the files and committed those, but Git is really [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[66],"tags":[],"_links":{"self":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/690"}],"collection":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/comments?post=690"}],"version-history":[{"count":7,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/690\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/media?parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/categories?post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/tags?post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}