Why does "git stash pop" right after "git stash --keep-index" result in conflicts?

git, git-stash

Solution

The problem comes from the `--keep-index`. The changes you stashed are in conflicts with the changes you already staged.

Here are commands you can use to reproduce

echo bar > foo
git add foo
echo baz > foo
git stash --keep-index
git stash pop #CONFLICT

In that case git doesn't know whether bar or baz should be present in foo...

The solution would be not to use the `--keep-index` argument or to commit the changes you added first (you can always amend your commit later)

You can also get your working directory in the same state that before using `git stash branch <branchname>` (you will then have to merge the branch)

Problem

I did: ``` $ git stash --keep-index $ git stash pop ``` and Git asks me to solve conflicts. Do I do something wrong? How can I stash unstaged files (test the programm) and then return everything back (so I've got all staged files untouched and unstaged files are back and are unstaged)?

Original source