<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Versioning Control on Blog of Jérémie Litzler</title>
        <link>https://iamjeremie.me/tags/versioning-control/</link>
        <description>Recent content in Versioning Control on Blog of Jérémie Litzler</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Fri, 24 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://iamjeremie.me/tags/versioning-control/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Remove File From Last Pushed Commit</title>
        <link>https://iamjeremie.me/post/2026-04/git-remove-file-from-last-pushed-commit/</link>
        <pubDate>Fri, 24 Apr 2026 00:00:00 +0000</pubDate>
        
        <guid>https://iamjeremie.me/post/2026-04/git-remove-file-from-last-pushed-commit/</guid>
        <description>&lt;img src="https://iamjeremie.me/images/2026-04-29-logo-of-git-scm.svg" alt="Featured image of post Remove File From Last Pushed Commit" /&gt;&lt;p&gt;To remove a file from the last pushed commit:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase -i HEAD~1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;In the editor, change &lt;code&gt;pick&lt;/code&gt; to &lt;code&gt;edit&lt;/code&gt;, save and close. Then:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;7
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;8
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;9
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rm --cached &amp;lt;file&amp;gt;        &lt;span class=&#34;c1&#34;&gt;# removes from tracking only&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# or&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rm &amp;lt;file&amp;gt;                 &lt;span class=&#34;c1&#34;&gt;# removes from tracking + disk&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git commit --amend
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase --continue
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push --force-with-lease   &lt;span class=&#34;c1&#34;&gt;# force push to overwrite remote&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;code&gt;--force-with-lease&lt;/code&gt; is safer than &lt;code&gt;--force&lt;/code&gt; as it fails if someone else pushed in the meantime. If it’s a shared branch, warn your team before force-pushing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;but-all-traces-of-the-files-commit-arent-gone&#34;&gt;But All Traces of the File’s Commit Aren’t Gone
&lt;/h2&gt;&lt;p&gt;Indeed, the file’s blob object still exists in &lt;code&gt;.git/objects&lt;/code&gt;. Git stores content as objects, and even after rewriting history, the old objects remain as &lt;strong&gt;dangling/unreachable objects&lt;/strong&gt; until garbage collected.&lt;/p&gt;
&lt;p&gt;To purge it (important if the file contained secrets):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git reflog expire --expire&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;now --all
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git gc --prune&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;now --aggressive
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;This removes unreachable objects from the local repository. But if you already pushed the original commit, the object may still exist on the remote (GitHub retains dangling objects for a while).
Therefore, for secrets, you should rotate them regardless.&lt;/p&gt;
&lt;div class=&#34;jli-notice jli-notice-tip&#34;  id=&#34;Follow me&#34; &gt;
    &lt;p class=&#34;jli-notice-title&#34;&gt;Follow me&lt;/p&gt;&lt;p&gt;Thanks for reading this article. Make sure to &lt;a href=&#34;https://x.com/LitzlerJeremie&#34;&gt;follow me on X&lt;/a&gt;, &lt;a href=&#34;https://iamjeremie.substack.com/&#34;&gt;subscribe to my Substack publication&lt;/a&gt; and bookmark my blog to read more in the future.&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Credit: Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
