Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pop git stash without triggering an auto-merge?
    text
    copied!<p>The short version of this question is this: how can I pop the <code>git</code> stash without triggering an auto-merge?</p> <hr> <p>Now for the longer version...</p> <p>Consider the following toy example of an alternative to <code>git stash ... + git pull ... + git pop</code>.</p> <p>First, <code>git status</code> shows that the only modification in the working directory is to some tracked file <code>foo</code>.</p> <pre><code># On branch master # Changes not staged for commit: # (use "git add &lt;file&gt;..." to update what will be committed) # (use "git checkout -- &lt;file&gt;..." to discard changes in working directory) # # modified: foo # no changes added to commit (use "git add" and/or "git commit -a") </code></pre> <p>Now, in order to reset the working directory to a clean state, as a pre-requisite for running <code>git pull</code>, I temporarily rename the modified file <code>foo</code> (to some untracked name), and restore the version of <code>foo</code> in <code>HEAD</code>...</p> <pre><code>% mv foo foo.$(date +%Y%m%dT%H%M%S) % git checkout foo % git status # On branch master # Untracked files: # (use "git add &lt;file&gt;..." to include in what will be committed) # # foo.20130508T110014 nothing added to commit but untracked files present (use "git add" to track) </code></pre> <p>OK, now I run <code>git pull</code>, which, for the sake of this example, we may assume is a fast-forward:</p> <pre><code>% git pull </code></pre> <p>Lastly, I restore the temporarily renamed <code>foo</code>.</p> <pre><code>% mv foo.20130508T110014 foo </code></pre> <p>...and I'm back to</p> <pre><code>% git status # On branch master # Changes not staged for commit: # (use "git add &lt;file&gt;..." to update what will be committed) # (use "git checkout -- &lt;file&gt;..." to discard changes in working directory) # # modified: foo # </code></pre> <p>This is the "moral equivalent" of a <code>git stash save + git pull + git stash pop</code>, EXCEPT that the former, and not the latter, <em>is immune to "merge conflicts"</em>, like this one:</p> <pre><code>% git stash save 'WIP' % git pull % git stash pop Auto-merging foo CONFLICT (content): Merge conflict in foo </code></pre> <p>How can I replicate the <code>rename-checkout-pull-rename</code> sequence above using <code>git stash save + ... + git stash pop</code>, <em>without</em> triggering an auto-merge?</p> <p>Incidentally, the <code>rename-checkout-...-rename</code> routine more closely represents what I expect from a command called <code>stash</code>. In other words: save the state of my working directory now, and replace it later. <em>There's no "merge" in this picture.</em></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