Git 说文件未合并,我无法提交,但文件似乎已合并

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6797845/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:24:16  来源:igfitidea点击:

Git says a file is unmerged and I can't commit, but the file seems to be merged

gitmergeconflict

提问by Adam Albrecht

I had about 12 file conflicts when I merged branches. I manually fixed all the conflicts and staged the files. But now when I try to commit, it says one of the files is unmerged.

合并分支时,我遇到了大约 12 个文件冲突。我手动修复了所有冲突并暂存了文件。但是现在当我尝试提交时,它说其中一个文件未合并。

U      app/models/disclosure_event.rb
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

When I type git status, it shows all the changed files, including "disclosure_event.rb", under Changes to be committed. It shows no files as unstaged. I've repeatedly tried to add the file, but it seems to do nothing. If I open the file, everything looks great.

当我输入 时git status,它会在Changes to be committed. 它没有显示未暂存的文件。我反复尝试添加该文件,但似乎什么也没做。如果我打开文件,一切看起来都很棒。

Any ideas? I'm completely stuck.

有任何想法吗?我完全被困住了。

回答by Ryan Stewart

I can't tell you what's wrong, but you might try

我不能告诉你出了什么问题,但你可以试试

git reset app/models/disclosure_even.rb
git add app/models/disclosure_even.rb

and then commit.

然后提交。

回答by alexkasko

I had exactly the same situation today on branches merging (not rebasing).

我今天在分支合并(不是变基)时遇到了完全相同的情况。

I spot, that file it errors on, in your case:

我发现,在你的情况下,文件错误:

U      app/models/disclosure_event.rb

was absent in git status. But is could be seen as unmerged in gitk GUI. It also was absent in working copy (moved to another place in my case).

在 git status 中不存在。但它可以被视为未合并到 gitk GUI 中。它也没有出现在工作副本中(在我的情况下移动到另一个地方)。

I tried git rm, and it solved the problem:

我试过了git rm,它解决了这个问题:

git rm app/models/disclosure_event.rb

回答by Md. Ranju Mia

Set the remote is originand the branch is master, and say you already have masterchecked out, might try the following:

设置遥控器 isorigin和分支 is master,并假设您已经master签出,可以尝试以下操作:

git fetch origin
git reset --hard origin/master

It will set the current branch and points it to the HEAD of the remote branch.

它将设置当前分支并将其指向远程分支的 HEAD。

回答by Ivan Danilov

I encountered such situation before with rebase. Git determines that you leave some files as they were before merge and thinks you still didn't merge them. That time I googled and find out many suggestions to do just git rebase --skip. It worked for me.

我之前用 rebase 遇到过这种情况。Git 确定您将某些文件保留为合并前的原样,并认为您仍然没有合并它们。那一次我用谷歌搜索并找到了很多建议git rebase --skip。它对我有用。

More detailed description of such case: http://git.661346.n2.nabble.com/BUG-git-rebase-is-confuse-if-conflict-resolution-doesn-t-produce-diff-td726597.html

这种情况的更详细描述:http: //git.661346.n2.nabble.com/BUG-git-rebase-is-confuse-if-conflict-resolution-doesn-t-produce-diff-td726597.html

Similar problem: Git rebase: conflicts keep blocking progress

类似问题:Git rebase:冲突不断阻碍进度

I'm not sure it is your case if you have merge, though.

不过,如果您进行了合并,我不确定是否是您的情况。

回答by Adam Albrecht

I tried the 2 suggestions without any luck. And I couldn't get it to reset back to HEAD, so I just re-cloned the repository and did the entire merge over and didn't have any issues. For what it's worth, I now highly recommend p4merge over vimdiff...

我在没有任何运气的情况下尝试了 2 个建议。我无法将它重置回 HEAD,所以我只是重新克隆了存储库并完成了整个合并,没有任何问题。对于它的价值,我现在强烈推荐 p4merge 而不是 vimdiff ...