在 git 中出现多个阶段条目的致命错误

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

Getting a fatal error in git for multiple stage entries

git

提问by Daniel Toebe

Using Git version 2.2.0 with unity game engine on OS X, and wanted to commit my code. I added everything and did not get an error message. then commit -m , and got this error message:

在 OS X 上使用 Git 版本 2.2.0 和统一游戏引擎,并想提交我的代码。我添加了所有内容,但没有收到错误消息。然后提交 -m ,并收到此错误消息:

fatal: multiple stage entries for merged file 'Assets/Prefabs/Resources'

Not noticing it I pushed, that didn't give an error message, in fact said Everything up-to-dateSo I checked bitbucket (where the repo is held) and it didn't show my commit. so I checked my local log and that also does not show my commit.

没有注意到我推送了它,并没有给出错误消息,实际上说Everything up-to-date所以我检查了 bitbucket(保存回购的地方)并且它没有显示我的提交。所以我检查了我的本地日志,这也没有显示我的提交。

I've looked into google for an answer... and nothing. what is this error? and how can I fix it?

我已经查看了谷歌的答案......什么也没有。这是什么错误?我该如何解决?

回答by VonC

The first workaround, which seems to work with recent versions of Git (2.3+, Q2+ 2015) is mentioned in grant's more up-to-date answer:

第一个解决方法似乎适用于最新版本的 Git(2.3+,Q2+ 2015)在grant最新答案中提到:

  1. Delete the index

    $ rm .git/index
    
  2. Add all

    $ git add -A
    
  3. Commit

    $ git commit -a
    
  1. 删除索引

    $ rm .git/index
    
  2. 全部添加

    $ git add -A
    
  3. 犯罪

    $ git commit -a
    


Original answer (late 2014)
The usual workaround is to:

原始答案(2014 年末)
通常的解决方法是:

  • clone again the remote repo into a new local repo
  • add the changes from the first repo to the second one:

    $ cd /patH/to/second/cloned/repo
    $ git --work-tree=/path/to/first/repo add .
    
  • 再次将远程仓库克隆到新的本地仓库中
  • 将第一个 repo 的更改添加到第二个:

    $ cd /patH/to/second/cloned/repo
    $ git --work-tree=/path/to/first/repo add .
    

You can see this error message in read-cache.c, discussed in this patch ("read-cache.c: Ensure unmerged entries are removed"), and introduced in the Git 2.2 commit.
Since this is so recent, it is possible that downgradingGit to 2.1 would be enough to not be affected by that patch.

您可以在 中看到此错误消息read-cache.c,在此补丁中进行了讨论(“ read-cache.c:确保删除了未合并的条目”),并在Git 2.2 提交中引入。
由于这是最近的事情,因此Git降级到 2.1 可能足以不受该补丁的影响。

The OP Daniel Toebeadds in the comments:

OP丹尼尔Toebe增加的评论

The issue happened on my macbook, which decided to fail on me, and another computer mishap put me way behind on my projects.

问题发生在我的 macbook 上,它决定在我身上失败,另一台计算机事故让我在我的项目上落后了。

回答by grant

I believe I encountered this issue because I added and committed changes and then deleted a file that I had just committed. If this sounds similar to your case, I recommend following the below to save re-cloning and manually adding in your changes.

我相信我遇到这个问题是因为我添加并提交了更改,然后删除了我刚刚提交的文件。如果这听起来与您的情况相似,我建议按照以下步骤保存重新克隆并手动添加更改。

I was able to fix this issue by deleting the .git/index file in my repository, similar to what @slider suggested (I believe he mistyped the path).

我能够通过删除我的存储库中的 .git/index 文件来解决这个问题,类似于@slider 建议的(我相信他输错了路径)。

rm .git/index

Then I had to add and commit my local changes again

然后我不得不再次添加并提交我的本地更改

git add -A
git commit -m "..."

I was then able to push remotely.

然后我就可以远程推送了。

What is the git index and how is it relevant?

什么是 git 索引,它是如何相关的?

What's The Deal With The Git Index?

Git 索引有什么关系?

The git “index” is where you place files you want committed to the git repository.

Before you “commit” (checkin) files to the git repository, you need to first place the files in the git “index”.

git“索引”是您放置要提交到 git 存储库的文件的位置。

在将文件“提交”(签入)到 git 存储库之前,您需要先将文件放在 git“索引”中。

I believe that by deleting this file, git will re-index the repo, create a new one and you're good to go. It solves this problem because the local repository is re-indexed without the file I deleted that caused all the fuss.

我相信通过删除这个文件,git 会重新索引 repo,创建一个新的,你就可以开始了。它解决了这个问题,因为本地存储库在没有我删除的文件的情况下重新索引,导致所有大惊小怪。

Edit: It seems like this is Mac related (based on comments) so if it helps I'm on OSX 10.10 and git version 2.3.4 installed through brew.

编辑:这似乎与 Mac 相关(基于评论)所以如果它有帮助我在 OSX 10.10 和通过 brew 安装的 git 版本 2.3.4。

回答by farincz

For project

对于项目

rm .git/index
git reset

after deleting index you need to recreate it by git reset

删除索引后,您需要通过 git reset 重新创建它

For submodule:

对于子模块:

Go to main project folder

转到主项目文件夹

rm .git/modules/your_project_structure/index
git reset --hard HEAD

回答by slider

You can remove Git index file from your project. In the root of your project, run the following command:

您可以从项目中删除 Git 索引文件。在项目的根目录中,运行以下命令:

rm .git/index

After that git it work.

在那个 git 之后它工作了。

回答by wqycsu

I try a different solution and it works for me. Below are my options

我尝试了不同的解决方案,它对我有用。以下是我的选择

#cd .git
#rm index
#cd ..
#git add .

回答by Emile Bergeron

If this happens in a submodule

如果这发生在子模块中

The index file is located inside the parent .gitdirectory:

索引文件位于父.git目录内:

.git/modules/your_project_structure/index

In a submodule, there are no directories named .git(at least in the project I'm working on), there's only a .gitfile which tells you (and git) where to look for the git directory of that project.

在子模块中,没有命名的目录.git(至少在我正在处理的项目中),只有一个.git文件告诉您(和 git)在何处查找该项目的 git 目录。

Git status shows changes that I didn't make

Git 状态显示我没有做的更改

After removing the index files, and doing a git reset, I found myself facing lots of inexplicable changes and a hard reset wasn't helping.

删除索引文件并执行git reset.

Warningyou'll lose all your changes, so commit them and push before continuing.

警告您将丢失所有更改,因此在继续之前提交并推送。

The index seemed corrupted, so I removed it with the following commands.

索引似乎已损坏,因此我使用以下命令将其删除。

git rm -rf --cached .
git reset --hard HEAD

回答by Oren

I just got this error with the Github Desktop Client (OSX). All I did was quit the app and reopened and then it started working.

我刚刚在 Github 桌面客户端 (OSX) 上遇到了这个错误。我所做的就是退出应用程序并重新打开,然后它开始工作。