当我尝试提交更改时,我得到这个错误:

error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty
fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt

我尝试了我得到的 git fsck:

error: object file .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71 is empty
fatal: loose object 03dfd60a4809a3ba7023cbf098eb322d08630b71 (stored in .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71) is corrupt

如何解决这个错误?


当前回答

这里有一个非常简单和快速的方法来处理这个问题,如果你有一个本地回购和所有你需要的分支和提交,如果你可以创建一个新的回购(或删除服务器的回购并在它的位置上创建一个新的):

在服务器上创建一个新的空回购(或删除旧的回购并在其位置上创建一个新的回购) 将本地副本的远程URL更改为指向新回购的远程URL。 将所有分支从本地回购推到新的服务器回购。

这将保存您在本地回购中拥有的所有提交历史和分支。

如果你在回购上有合作者,那么我认为在很多情况下,你的合作者所要做的就是改变他们本地回购的远程URL,并有选择地推送任何他们拥有的服务器没有的提交。

当我遇到同样的问题时,这个解决方案对我很有效。我有一个合作者。在我将本地回购推到新的远程回购后,他只是将本地回购更改为指向远程回购URL,一切都正常工作。

其他回答

我解决了这个问题,删除了git fsck检测到的各种空文件,然后运行一个简单的git拉。

我感到失望的是,现在即使文件系统实现了日志记录和其他“事务性”技术来保持文件系统正常运行,Git也会因为设备上的电源故障或空间问题而进入损坏状态(并且无法自行恢复)。

在我的例子中,出现这个错误是因为我正在输入提交消息,而我的笔记本关机了。

我执行了以下步骤来修复错误:

git checkout -b backup-branch # Create a backup branch git reset --hard HEAD~4 # Reset to the commit where everything works well. In my case, I had to back four commits in the head, that is until my head be at the point before I was typing the commit message. Before doing this step, copy the hash of the commits you will reset. In my case I copied the hash of the four last commits. git cherry-pick <commit-hash> # Cherry pick the reset commits (in my case are four commits, so I did this step four times) from the old branch to the new branch. git push origin backup-branch # Push the new branch to be sure everything works well git branch -D your-branch # Delete the branch locally ('your-branch' is the branch with problem) git push origin :your-branch # Delete the branch from remote git branch -m backup-branch your-branch # Rename the backup branch to have the name of the branch that had the problem git push origin your-branch # Push the new branch git push origin :backup-branch # Delete the backup branch from remote

我在使用虚拟机时经常遇到这个问题。

对我来说,以下工作:

cd /path/to/your/project
rm -rf .git

如果你想为自己节省一些下载-进入你的文件资源管理器,删除文件夹中已经提交的所有文件,并保留在你的/vendor和/node_modules(我使用PHP Composer和npm)文件夹中。

然后创建一个新的存储库:

git init

添加遥控器

git remote add origin ssh://git@github.com/YourUsername/repoName.git

然后去取树枝/全部

git fetch origin somebranch

大家来看看

git checkout somebranch

那么你应该在错误之前的点。

移动你的应用文件夹做一个备份,即mv app_folder app_folder_bk(它就像一个git stash) Git克隆your_repository 最后,打开一个合并工具(我在Linux上使用Meld diff查看器,在Windows上使用WinMerge),从右边(app_folder_bk)复制更改到左边(new app_folder)(这就像一个git stash应用)。

这是所有。也许这不是最好的方法,但我认为它很实用。

事实上,我也有同样的问题。

在尝试此操作之前,请准备一份代码副本。

我刚刚做了 git重置头~

我的最后一次承诺也没有兑现。然后我又犯了一次,问题就解决了!