Git stash pop- needs merge, unable to refresh index

后端 未结 10 1921
遥遥无期
遥遥无期 2020-12-12 20:00

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         


        
10条回答
  •  误落风尘
    2020-12-12 20:28

    Well, initially, we should know what caused the error to happen, then the solution will be easy. The reason have already been pointed out by the accepted answer, but it is somehow incomplete (also the solution).

    The problem is, one or more files had conflict(s) previously, but Git sees them as unresolved. Yes, you might already edited those files and resolved the conflicts, but Git does not know about that. You should tell Git "Hey, there are no more 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.

    Remember, git status can tell you what Git knows now. If there are some unresolved merge conflicts to Git, then 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. From this, I personally understand that, "Unmerged paths are those you should either move into staged or unstaged areas, as Git can work only with these two areas".

    So, to tell Git the conflicts have been resolved, you should either move these changes to staged or unstaged areas. In recent versions of Git, when you do a git status, it tells you how (woah! You should ask yourself how you haven't seen this yet?):

    $ git status
    ...
    Unmerged paths:
      (use "git restore --staged ..." to unstage)
      (use "git add ..." 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 possibly 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).

提交回复
热议问题