gitgit-stash

How to resolve "delete/modify" conflict caused by "git stash apply"


I recently did a git stash, then did some work on the branch and committed it, and got these errors when trying to do a git stash apply:

CONFLICT (delete/modify): app/controllers/orders_controller.rb deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of app/controllers/orders_controller.rb left in tree.
CONFLICT (content): Merge conflict in app/models/product.rb

git status shows the following:

 $ git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 16 commits.
# Unmerged paths: 
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   deleted by us:      app/controllers/orders_controller.rb
#   both modified:      app/models/product.rb

The file marked "delete/modify" was a new file that I added and hadn't yet committed before the stash.
I'd like to be back in the state I was in before the git stash -- having uncommitted local changes. Can you suggest how to make that happen?

Thanks.


Solution

  • You are popping the stash onto a different state; state that has one additional commit. And worse, the commit has introduced merge conflicts, as you know.

    You have two options:

    1. pop that stash onto the latest commit and resolve the conflicts
    2. pop the stash onto the prior commit.

    Sounds like #2 is what you want to do. Use:

        git stash branch new_branch [<stash>]  # <stash> will be the last one if not provided.