I can't pop my stash because I merged a branch which apparently conflicts with my stash and now my stash is seemingly unable to be popped.
app.coffee: needs merge unable to refresh index Anyone know how to resolve this?
I can't pop my stash because I merged a branch which apparently conflicts with my stash and now my stash is seemingly unable to be popped.
app.coffee: needs merge unable to refresh index Anyone know how to resolve this?
First, check git status.
As the OP mentions,
The actual issue was an unresolved merge conflict from the merge, NOT that the stash would cause a merge conflict.
That is where git status would mention that file as being "both modified"
Resolution: Commit the conflicted file.
Solution: in this case, simply add and commit your local file.
Actually, just git add -- yourFile, or (if you don't want those changes) git reset -- yourFile (to unstage it) is enough to get past the error message.
If you do not want to commit, just git add yourFile is enough.
You can then git stash the rest if you want.
You can find a similar situation 4 days ago at the time of writing this answer (March 13th, 2012) with this post: "‘Pull is not possible because you have unmerged files’":
julita@yulys:~/GNOME/baobab/help/C$ git stash pop help/C/scan-remote.page: needs merge unable to refresh index What you did was to fix the merge conflict (editing the right file, and committing it):
See "How do I fix merge conflicts in Git?"
What the blog post's author did was:
julita@yulys:~/GNOME/baobab/help/C$ git reset --hard origin/mallard-documentation HEAD is now at ff2e1e2 Add more steps for optional information for scanning. I.e. aborting the current merge completely, allowing the git stash pop to be applied.
See "Aborting a merge in Git".
Those are your two options.
git add alone can be enough.Here's how I solved the issue:
git add . without committing fixes the issue for me.Its much simpler than the accepted answer. You need to:
Check git status and unmerged paths under it. Fix the conflicts. You can skip this step if you'd rather do it later.
Add all these files under unmerged paths to index using git add <filename>.
Now do git stash pop. If you get any conflicts these will again need to be resolved.
I was having this issue, then resolving the conflict and commiting, and doing git stash pop again was restoring the same stash again (causing the same conflict :-( ).
What I had to do (WARNING: back up your stash first) is git stash drop to get rid of it.
Well, initially, we should know the root of the error, then the solution will become easy. The reason has already been pointed out by the accepted answer, but it's somehow incomplete (and also the solution).
The problem is, one or more files had conflicts previously, and Git still sees them as unresolved. Although you may already edited those files and resolved the conflicts, but Git is not aware of.
In this case, you should inform Git: "Hey, there are no conflicts from the previous merge!". Note that, the merge is not necessarily caused by a git merge, but also by a git stash pop, for example.
Generally, git status can tell you what Git knows now. If there are some unresolved merge conflicts to Git, it is shown in a separated Unmerged paths section, with the files marked as both modified (always?). If you have noticed, this section is between two staged and unstaged sections. This means, unmerged paths are those you should either move into staged or unstaged areas, as Git can work only with these two.
Even in recent versions of Git, when you do a git status, it tells you the how (woah! You should ask yourself how you haven't seen this yet):
$ git status ... Unmerged paths: (use "git restore --staged <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: path/to/file.txt ... So, to stage it (and maybe commit it):
git add path/to/file.txt And to make it unstaged (e.g. you don't want to commit it now):
git restore --staged path/to/file.txt Note: Forgetting to write --staged option could spawn a super-hungry dragon to eat your past two days, in the case of not using a good text-editor or IDE.
Note: While git restore command is experimental yet, it should be stable enough to be used (thanks to a comment by @VonC, refer to it for more details on that).
If anyone is having this issue outside of a merge/conflict/action, then it could be the git lock file for your project causing the issue.
git reset fatal: Unable to create '/PATH_TO_PROJECT/.git/index.lock': File exists. rm -f /PATH_TO_PROJECT/.git/index.lock git reset git stash pop reset command. Could you explain why this will work?I was facing the same issue because i have done some changes in my develop branch and then want to go to the profile branch. so i have stash the changes by
git stash then in profile branch i have also done some changes and then want to come back again to the develop so i have to stash the changes again by
git stash but when i come to develop branch and tried to git the stash changes by
git stash apply so i was getting error need merge
to solve this issue first i have to check the stash list by
git stash list so it shows the list of stashes in my case there were 2 stashes the name of the stashes are displaying like this stash@{0},stash@{1}
I have need changes from stash@{1} so when i try to get it by this command
git stash apply stash@{1} so was getting error needs merge
so now to solve this issue check the status of your files
git status so it was giving error that "both modified" so to solve this run
git add . it will add the missing modified files now again check the status
git status so now there is no error now can apply stash
git stash apply stash@{1} you can do this process for any number of stash files.