Suppose that upon running git stash pop
, one gets a CONFLICT
message (resulting from a failed auto-merging attempt).
Is there a quick way to tell git
to resolve all conflicts in favor of the stash that was just popped?
EDIT: I just wrote the following script to test the two alternatives proposed. It
- creates a fresh git repo in the directory
/tmp/$1
, andcd
s to it; - creates a first version of a file and commits it;
- makes some changes to the file and stashes the file;
- makes other changes to the file (including both conflicting and non-conflicting changes), and commits these changes; and finally
- pops the stash
This sets the stage for comparing the two proposed methods. Here's the script:
shopt -s expand_aliases
alias gcommit='git commit -q --allow-empty-message -m ""'
alias gmerge='git merge -q --no-edit'
TESTDIR=/tmp/$1
rm -rf "$TESTDIR"
mkdir -p "$TESTDIR"
cd "$TESTDIR"
git init -q
touch chiasmus.txt
git add . && gcommit
cat <<EOF > chiasmus.txt
ask
what
...
EOF
gcommit -a
cat <<EOF > chiasmus.txt
ask
not
what
your country can do for you
...
EOF
git stash -q
cat <<EOF > chiasmus.txt
quote:
ask
what
you can do for your country
...
jfk
EOF
gcommit -a
git stash pop -q
Then I ran
% bash gittest.sh checkout
% bash gittest.sh merge
% cd /tmp/checkout
% git checkout --theirs $(git diff --name-only --diff-filter=U)
% cd /tmp/merge
% git reset -q --hard
% git merge -q --no-edit --squash -Xtheirs stash
Auto-merging chiasmus.txt
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
% diff /tmp/{checkout,merge}/chiasmus.txt
0a1
> quote:
5a7
> jfk
Therefore, it looks like the "checkout" option does lose the non-conflicting changes. As it happens, though, this option more closely matches what I was really after, namely, have git pop
behave more closely to what I expect it to do: return me to where I was when I ran git stash
, period. No auto-merge, etc. (IOW, my question, as asked, really did not accurately reflect what I was after. It's as if meagar read my mind somehow.)