<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Git on Vedant Andhale</title>
    <link>https://www.vedant.me/tags/git/</link>
    <description>Recent content in Git on Vedant Andhale</description>
    <image>
      <url>https://www.vedant.me/</url>
      <link>https://www.vedant.me/</link>
    </image>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 10 Sep 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.vedant.me/tags/git/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Git restore: choose the source and destination</title>
      <link>https://www.vedant.me/notebook/git-restore-beats-checkout-for-files/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0000</pubDate>
      
      <guid>https://www.vedant.me/notebook/git-restore-beats-checkout-for-files/</guid>
      <description>Separate unstaging a file from discarding working-tree edits with git restore.</description>
      <content:encoded><![CDATA[<p><code>git restore</code> becomes easier to remember when you ask two questions: where is the content coming from, and where is it going?</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl"><span class="c1"># Copy the index version into the working tree.</span>
</span></span><span class="line"><span class="cl">git restore -- path/to/file
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Reset the staged version to HEAD; keep working-tree edits.</span>
</span></span><span class="line"><span class="cl">git restore --staged -- path/to/file
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Copy one file from a chosen commit into the working tree.</span>
</span></span><span class="line"><span class="cl">git restore --source<span class="o">=</span>HEAD~1 -- path/to/file
</span></span></code></pre></td></tr></table>
</div>
</div><p>The first command discards <strong>unstaged</strong> edits to that tracked file. It does not necessarily restore the last commit: its default source is the index, which may contain staged changes.</p>
<p>With <code>--staged</code>, the default source is <code>HEAD</code>. That makes the second command useful for unstaging without throwing away the edited file.</p>
<p>Before restoring working-tree content, inspect <code>git diff -- path/to/file</code>; inspect staged content with <code>git diff --cached -- path/to/file</code>. Uncommitted content overwritten by restore may not be recoverable through Git.</p>
<p>The <code>--</code> separates options from file paths. It makes the intended target explicit and avoids ambiguity when a path resembles an option.</p>
<p>Reference: <a href="https://git-scm.com/docs/git-restore">git-restore documentation</a>.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
