git pull我在编辑之前忘记了我的代码;当我提交新代码并尝试推送时,我收到错误“无法推送”。
那时我做了一个git pull突出显示冲突的文件。我消除了冲突,但我不知道从这里做什么。
我再次尝试,git commit但它说“提交是不可能的,因为你有未合并的文件”:
error: Committing is not possible because you have unmerged files.
如果您已经解决了冲突,您需要使用 将文件添加到阶段git add [filename],然后正常提交。
你需要做两件事。首先添加更改
git add .
git stash
git checkout <some branch>
它应该解决你的问题,因为它解决了我。
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 2.23(2019 年 8 月)以来,您现在有了一个捷径:git restore --staged [filepath]. 使用此命令,您可以忽略冲突文件,而无需添加和删除它。
例子:
> 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
我有一个类似的问题,归结为删除“未合并路径”下的文件
这些文件必须使用删除git rm
所以从上面的错误。要解决此问题,您所要做的就是还原您的代码。( git revert HEAD) 然后git pull重做您的更改,然后git pull再一次,并且能够提交或合并而没有错误。