Git 坏对象desktop.ini

问题描述 投票:0回答:4

我的电脑上曾经有 GoogleDrive,它可以将我的所有代码上传到该驱动器上。我当时正在主分支上工作,因为我在 GitHub 上得到了这个项目,所以我删除了所有的desktop.ini 文件并尝试拉取该项目以更新我的同事所做的更改,但收到了此错误。

我一开始并没有想到这个问题,因为 GoogleDrive 需要几分钟的时间来制作所有的desktop.ini,但是当它完成时,却引起了问题。

> git pull pmo main
remote: Enumerating objects: 85, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 59 (delta 25), reused 59 (delta 25), pack-reused 0
Unpacking objects: 100% (59/59), 6.63 KiB | 218.00 KiB/s, done.
fatal: bad object refs/desktop.ini
error: https://github.com/*******/*******.git did not send all necessary objects

我尝试使用命令

rm
删除 .git/refs/desktop.ini,但它说我无权访问它,即使在 powershell 中也是如此。

github git-pull
4个回答
3
投票

如果将 Google 云端硬盘文件夹(及其子文件夹)共享给其他用户,则会为当前文件夹及其所有子文件夹创建一个

desktop.ini
文件。因此,如果此共享文件夹包含 git 存储库,则
.git
文件夹和所有子文件夹(例如,
refs
objects
,Git 存储其自己的数据)将包含
desktop.ini
。 Git 期望
.git
下的所有文件仅包含 Git 数据,因此它无法理解
desktop.ini
的文件内容。看起来删除所有
desktop.ini
并不是一个好的解决方案,因为
desktop.ini
会在几分钟后重新出现。

对我来说,停止共享谷歌驱动器文件夹是可行的。它会自动删除

desktop.ini
并且不会重新生成。


0
投票

这就是为什么在网络同步驱动器中工作的原因:git pull/push/clone 不能很好地与 Google Drive 附带的并发同步配合使用。

最好保存在该驱动器上 a

git bundle
(将存储库存储在 one 文件中),同时通过远程 GitHub 存储库(在普通文件夹中本地克隆)与其他人协作


Ez0r评论中建议使用像Everything这样的工具来搜索并删除任何出现的

desktop.ini


0
投票

您还可以添加一个名为 .gitignore 的新文件;在文件中添加 *.ini ,git 将忽略这些文件。您可以在如何摆脱 Git 子模块未跟踪状态找到更多信息?Github 上有示例https://github.com/github/gitignore


0
投票

删除所有desktop.ini文件对我有用,但无法手动制作(有很多)。

我使用了以下代码(取自 SharifMrCreed https://github.com/mhutchie/vscode-git-graph/issues/611):

folder_path = <introduce_your_folder_path>

for root, dirs, files in os.walk(folder_path):
    for filename in files:
        if filename.lower() == "desktop.ini":
            file_path = os.path.join(root, filename)
            try:
                os.remove(file_path)
                print(f"Deleted {file_path}")
            except Exception as e:
                print(f"Error deleting {file_path}: {e}")

我希望这有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.