The stash can't be reverse-applied as a patch because of the conflict markers. You'd still have to do something like reverse-patching for files that were modified in both places without conflict. To see if the file contains local modifications. To see if the stash modified a file, and something like git diff stash - path/to/file Of you could handle it file by file, using git stash show -name-only Then you would resolve the conflicts with checkout -ours, and reverse-apply the rest of the patch. There are two ways to go about fixing this:īuilding on what you were trying to do before, you could store the patch from the stash and remove the entries for files that were conflicted. Ok, so cases 1 and 2 take no action, and 4 is easy to find and resolve. It again looks pretty much like cases 2 and 3, and to fix it you need to separate your changes from those added by the stash. Restore Git Stash Changes Using Git Stash Apply. The sections below explain both ways of restoring a Git stash. automatic merge resolution combined the changes successfully). There are two ways to restore a Git stash: Using git stash pop. You can restore your version by saying git checkout -ours - file/with/conflicting/changesĥ) You had applied local changes to the file, and the stash applied changes to the same file, but the changes are not in conflict (i.e. In this case, the conflict-marked version of the file is in the work tree. This looks pretty much like case 2, so knowing the difference is the first challenge (see below) once you identify a file in this state, you could revert this file to the previously-committed version (but might not want to just yet again, see below) git checkout HEAD - file/with/only/stashed/changesĤ) You had applied local changes to the file, and the stash applied conflicting changes to the same file. The index contains the file as modified by the stash. Your locally-changed version is in the index, and you can leave this file alone.ģ) You had not applied local changes to the file, and the stash did apply changes to it. Nothing to see here.Ģ) You applied local changes to the file, and the stash did not apply changes to the file. So now there are (at least) five possible states for each file:ġ) Neither your local changes nor the stash applied changes to the file. It can be a bit of a pain when there are conflicts, though, because now it updates the index for conflict resolution. It requires that the work tree match the index, and it is only expected to write to the work tree, so it would seem easy to undo. Generally git stash apply is a fairly safe command. I'll go into more detail about that at the end if you want to dig into that, but more importantly: what to do instead? The problem with reverse-applying the stash is due to the merge conflicts.
2 Comments
|