As far as I'm aware, git stash
saves a diff between the working tree and , the state of the working tree, as well as the index. You can see this by running HEAD
, it doesn't save the indexgit log --graph stash@{0}
after creating a stash.
git stash pop
has an option --index
, with this documentation:
If the --index option is used, then tries to reinstate not only the working tree’s changes, but also the index’s ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally).
I don't understand this documentation. The second sentence in the quoted documentation is confusing to me.
Why do merge conflicts unexpectedly happen? For example:
$ git init test
$ cd test
$ echo initial > file
$ git add file
$ git commit -m initial
$ echo a >> file
$ git add file
$ echo b >> file
$ git stash save --keep-index
$ git stash pop --index
Auto-merging file
CONFLICT (content): Merge conflict in file
I don't understand why a merge conflict happens in the last step. What I want to happen is for git stash pop --index
to recognise that the index is already in the correct state, and to change the working tree files to match the stashed files.