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.
Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards. If the --index option is used, then tries to reinstate not only the working tree's changes, but also the index's ones.
When popping out commits using the git stash pop command, you will have some merge conflicts sometimes, you can move to resolve those conflicts or abort the whole process. command. This has worked for me.
To retrieve changes out of the stash and apply them to the current branch you're on, you have two options: git stash apply STASH-NAME applies the changes and leaves a copy in the stash. git stash pop STASH-NAME applies the changes and removes the files from the stash.
Remove your stash The only way to revert it is if you didn't close the terminal after deleting the stash. If you no longer need a particular stash, you can delete it with: $ git stash drop <stash_id> . Or you can delete all of your stashes from the repo with: $ git stash clear .
This worked for me.
Do a-
git mergetool
Then you would be asked to pick the modified or deleted file or abort, and after this do one more time-
git mergetool
This would resolve the merge conflict and you can stash pop your changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With