Git merge error “commit is not possible because you have unmerged files”

后端 未结 7 1111
陌清茗
陌清茗 2020-11-29 17:11

I forgot to git pull my code before editing it; when I committed the new code and tried to push, I got the error "push is not possible".

At tha

相关标签:
7条回答
  • 2020-11-29 17:19

    This error occurs when you resolve the conflicts but the file still needs to be added in the stage area. git add . would solve it. Then, try to commit and merge.

    0 讨论(0)
  • 2020-11-29 17:20

    I've had a similar issue which boiled down to removing files under "unmerged paths"

    Those files had to be removed using git rm

    0 讨论(0)
  • 2020-11-29 17:21

    You need to do two things. First add the changes with

    git add .
    git stash  
    
    git checkout <some branch>
    

    It should solve your issue as it solved to me.

    0 讨论(0)
  • 2020-11-29 17:21

    Since git 2.23 (August 2019) you now have a shortcut to do that: git restore --staged [filepath]. With this command, you could ignore a conflicted file without needing to add and remove that.

    Example:

    > git status
    
      ...
      Unmerged paths:
        (use "git add <file>..." to mark resolution)
          both modified:   file.ex
    
    > git restore --staged file.ex
    
    > git status
    
      ...
      Changes not staged for commit:
        (use "git add <file>..." to update what will be committed)
        (use "git restore <file>..." to discard changes in working directory)
          modified:   file.ex
    
    
    0 讨论(0)
  • 2020-11-29 17:26

    So from the error above. All you have to do to fix this issue is to revert your code. (git revert HEAD) then git pull and then redo your changes, then git pull again and was able to commit or merge with no errors.

    0 讨论(0)
  • 2020-11-29 17:28

    You can use git stash to save the current repository before doing the commit you want to make (after merging the changes from the upstream repo with git stash pop). I had to do this yesterday when I had the same problem.

    0 讨论(0)
提交回复
热议问题