Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As <a href="https://stackoverflow.com/a/22555169/6309">mentioned below</a>, and detailed in "<a href="https://stackoverflow.com/a/1105666/6309">How would I extract a single file (or changes to a file) from a git stash?</a>", you can apply use <a href="http://git-scm.com/docs/git-checkout" rel="noreferrer"><code>git checkout</code></a> or <a href="http://git-scm.com/docs/git-show" rel="noreferrer"><code>git show</code></a> to restore a specific file.</p> <pre><code>git checkout stash@{0} -- &lt;filename&gt; </code></pre> <p>(As <a href="https://stackoverflow.com/questions/15264553/how-to-unstash-only-certain-files/15264717#comment79042145_15264717">commented</a> by <a href="https://stackoverflow.com/users/403616/jaime-m">Jaime M.</a>, for certain shell like tcsh where you need to escape the special characters, the syntax would be: <code>git checkout 'stash@{0}' -- &lt;filename&gt;</code>)</p> <blockquote> <p>or to save it under another filename:</p> </blockquote> <pre><code>git show stash@{0}:&lt;full filename&gt; &gt; &lt;newfile&gt; </code></pre> <blockquote> <p>(note that here <code>&lt;full filename&gt;</code> is full pathname of a file relative to top directory of a project (think: relative to <code>stash@{0}</code>)).</p> </blockquote> <p><a href="https://stackoverflow.com/users/469294/yucer">yucer</a> suggests <a href="https://stackoverflow.com/questions/15264553/how-to-unstash-only-certain-files/15264717?noredirect=1#comment63627960_15264717">in the comments</a>:</p> <blockquote> <p>If you want to select manually which changes you want to apply from that file:</p> </blockquote> <pre><code>git difftool stash@{0}..HEAD -- &lt;filename&gt; </code></pre> <p><a href="https://stackoverflow.com/users/970301/vivek">Vivek</a> adds <a href="https://stackoverflow.com/questions/15264553/how-to-unstash-only-certain-files/15264717?noredirect=1#comment67306500_15264717">in the comments</a>:</p> <blockquote> <p>Looks like "<code>git checkout stash@{0} -- &lt;filename&gt;</code>" restores the version of the file as of the time when the stash was performed -- it does <em>NOT</em> apply (just) the stashed changes for that file.<br> To do the latter: </p> </blockquote> <pre><code>git diff stash@{0}^1 stash@{0} -- &lt;filename&gt; | git apply </code></pre> <p>(as <a href="https://stackoverflow.com/questions/15264553/how-to-unstash-only-certain-files/15264717?noredirect=1#comment70115895_15264717">commented</a> by <a href="https://stackoverflow.com/users/1172352/peterflynn">peterflynn</a>, you might need <code>| git apply -p1</code> in some cases, removing one (<code>p1</code>) leading slash from traditional diff paths)</p> <hr> <p>As commented: "unstash" (<code>git stash pop</code>), then:</p> <ul> <li>add what you want to keep to the index (<code>git add</code>)</li> <li>stash the rest: <code>git stash --keep-index</code></li> </ul> <p>The last point is what allows you to keep some file while stashing others.<br> It is illustrated in "<a href="https://stackoverflow.com/questions/3040833/how-to-stash-only-one-file-out-of-multiple-files-that-have-changed">How to stash only one file out of multiple files that have changed</a>".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload