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