GIT 合并错误“无法提交,因为您有未合并的文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12961752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GIT merge error "commit is not possible because you have unmerged files"
提问by Kiarash
so I forgot to pull my code before editing it and then when I committed the new code and tried to push, I got the error push is not possible, at that point I did a "git pull" which made some files with conflict highlighted. I removed the conflicts but I don't know what to do from here..
所以我在编辑之前忘记拉我的代码,然后当我提交新代码并尝试推送时,我得到错误推送是不可能的,那时我做了一个“git pull”,它突出了一些冲突的文件。我删除了冲突,但我不知道从这里开始做什么..
I tried to git commit
again but it says "commit is not possible because you have unmerged files"
我git commit
再次尝试,但它说“提交是不可能的,因为你有未合并的文件”
回答by jonnystoten
If you have fixed the conflicts you need to add the files to the stage with git add [filename]
, then commit as normal.
如果您已经修复了需要使用 将文件添加到阶段的冲突git add [filename]
,然后照常提交。
回答by Prabhakar Undurthi
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.
它应该可以解决您的问题,就像它对我的解决方案一样。
回答by muman
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.
您可以git stash
在执行要进行的提交之前使用保存当前存储库(在将来自上游存储库的更改与 合并之后git stash pop
)。昨天遇到同样的问题时,我不得不这样做。
回答by Priyanka Arora
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.
当您解决冲突但仍需要将文件添加到阶段区域时,会发生此错误。git 添加。会解决它。然后,尝试提交和合并。
回答by appdesigns
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.
所以从上面的错误。解决此问题所需要做的就是还原您的代码。( git revert HEAD
) 然后git pull
然后重做您的更改,然后git pull
再次并且能够提交或合并而没有错误。
回答by Macabeus
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.
由于git的2.23(2019八月)你现在有一个快捷方式做到这一点:git restore --staged [filepath]
。使用此命令,您可以忽略冲突文件而无需添加和删除它。
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
回答by Yann VR
I've had a similar issue which boiled down to removing files under "unmerged paths"
我有一个类似的问题,归结为删除“未合并路径”下的文件
Those files had to be removed using git rm
必须使用删除这些文件 git rm