<?xml version="1.0" encoding="UTF-8"?>
<guide>
  <body>&lt;p&gt;Don&amp;#8217;t you hate when you can&amp;#8217;t remove that file full of cleartext passwords from your github account?  Even if you &lt;code&gt;git rm&lt;/code&gt; it, it still is accessible in previous versions of the tree.  So, you need to rewrite the entire tree.  Fortunately, this is really easy with git.&lt;/p&gt;
&lt;h2&gt;How?&lt;/h2&gt;
&lt;pre class=&quot;console&quot;&gt;
git filter-branch -f --index-filter 'git update-index --remove filename' HEAD
git push --force --verbose --dry-run
git push --force
&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;filename&lt;/code&gt; is what you want to remove.  Now, when you browse past revisions, the file will be gone!&lt;/p&gt;
&lt;p&gt;&lt;em&gt;You will need to do &lt;code&gt;git push --force&lt;/code&gt; to push your changes, as this is no longer a fast forward push (the history and parents have been rewritten)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To retain tags you must specify &lt;code&gt;--tag-name-filter &quot;cat&quot;&lt;/code&gt; but note that &lt;strong&gt;this will overwrite your existing tags&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When doing this I usually create a backup like this:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
cd .git
mkdir backup
cp -r refs backup/refs
cp packed-refs backup
&lt;/pre&gt;
&lt;p&gt;since often I run filter-branch several times and you must delete &lt;code&gt;refs/original&lt;/code&gt; between runs.&lt;/p&gt;
&lt;h2&gt;An Improved Method&lt;/h2&gt;
&lt;p&gt;The method given above actually rewrites the whole repository history.  Usually, you&amp;#8217;ll only want to rewrite it from the revision the sensitive data was introduced:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
git filter-branch -f --index-filter 'git update-index --remove filename' &amp;lt;introduction-revision-sha1&amp;gt;..HEAD
git push --force --verbose --dry-run
git push --force
&lt;/pre&gt;
&lt;p&gt;Where introduction-revision-sha1 is the SHA1 that the file was first committed to the repository.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html&quot;&gt;git-filter-branch documentation&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#cleaning-up-history&quot;&gt;Git user manual &amp;#8211; Cleaning up history&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</body>
  <created-at type="datetime">2008-04-27T08:39:04-07:00</created-at>
  <id type="integer">43</id>
  <permalink>completely-remove-a-file-from-all-revisions</permalink>
  <title>Completely remove a file from all revisions</title>
  <updated-at type="datetime">2009-10-22T09:17:13-07:00</updated-at>
  <user-id type="integer">62842</user-id>
</guide>
