我的电脑突然关闭,现在我所从事的项目的 Git 存储库有缺陷。我安装了 Git 2.20.1。 我立即创建了项目文件夹的备份副本以使用原始文件夹。我有我不想失去的地方分支机构。
$ git status
error: object file .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3 is empty
fatal: loose object c78e67bcad2ea132e3df8f80bb42b4804ab4f2a3 (stored in .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3) is corrupt
短路输出:
$ git fsck --name-objects
error: object file .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84 is empty
error: unable to mmap .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84: No such file or directory
error: 04f338bf0dc0770b841b291af6cdd4c9130edb84: object corrupt or missing: .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84
error: object file .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850 is empty
error: unable to mmap .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850: No such file or directory
error: 2e07479ec010e5b459387d841a576e1ead97f850: object corrupt or missing: .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850
error: object file .git/objects/34/b03409d09382c44f50409e4388850ca9c82c77 is empty
error: unable to mmap .git/objects/34/b03409d09382c44f50409e4388850ca9c82c77: No such file or directory
...
error: object file .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3 is empty
error: unable to mmap .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3: No such file or directory
error: c78e67bcad2ea132e3df8f80bb42b4804ab4f2a3: object corrupt or missing: .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3
error: object file .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7 is empty
error: unable to mmap .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7: No such file or directory
error: e519b2fbf083f68694af97ccddf46bc28c6ee8f7: object corrupt or missing: .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7
error: object file .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e is empty
error: unable to mmap .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e: No such file or directory
error: ec289b8e8d17c47644d5bdbfbfc8b2957d2a430e: object corrupt or missing: .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e
error: object file .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4 is empty
error: unable to mmap .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4: No such file or directory
error: ed33778ddc07a26a37c6f200f35ffee12e365ea4: object corrupt or missing: .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4
error: object file .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70 is empty
error: unable to mmap .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70: No such file or directory
error: f65686bed85025fd7adbf209ba93846b18800d70: object corrupt or missing: .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70
error: object file .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38 is empty
error: unable to mmap .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38: No such file or directory
error: fdcdc518b01c670cd38c15903fd3e84554114d38: object corrupt or missing: .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38
Checking object directories: 100% (256/256), done.
Checking objects: 100% (40855/40855), done.
error: refs/remotes/origin/colors-housekeeping: invalid sha1 pointer 0000000000000000000000000000000000000000
error: bad ref for .git/logs/refs/remotes/origin/colors-housekeeping
error: object file .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e is empty
fatal: loose object ec289b8e8d17c47644d5bdbfbfc8b2957d2a430e (stored in .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e) is corrupt
colors-housekeeping
是一个已经合并到master
的分支,之后我已经编辑了其他文件,提交并合并了另一个分支。
我可以采取哪些步骤来修复损坏的对象?
相关
- 如何恢复因硬盘故障损坏的 Git 对象?
- 如何修复从树到树的git错误断开的链接?
- git - 从坏树对象中恢复?
当我克隆的存储库将其默认分支从master
重命名为main
时,我就发生这种情况。
错误是:
错误: 引用/远程/源/头: 无效的 sha1 指针 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
让我们看看磁盘上的指针文件:
$ cat .git/refs/remotes/origin/HEAD
ref: refs/remotes/origin/master
编辑该文件并用main
替换master
后,我再次能够毫无错误地获取/fsck/gc。
error: unable to mmap...
是一个错误,invalid sha1 pointer 000000...
是另一个错误。
对于任何在这里只有sha1指针错误但没有mmap错误的人(像我一样(:
sha1 指针错误可能意味着预期的指针文件不存在。refs/remotes/origin/colors-housekeeping
可能包含以下内容:ref: refs/remotes/origin/notexistingbranch
or:6ca0197d8f15f381d67e3502e678ca3d17dbbea2
但找不到此文件 (ref
( 或 commit-id。在这两种情况下,您都可以通过在文件中写入任何已知的提交 ID 或指向有效提交 ID 的指针来修复错误。换句话说,您将分支提交的缓存值重新分配origin/colors-housekeeping
。当你从origin
获取时,git 会再次在refs/remotes/origin/colors-housekeeping
中写入正确的origin/colors-housekeeping
提交 id。
我遇到了同样的问题,这就是我解决它的方式:
编辑文件:.git/refs/heads/colors-housekeeping
将提交 ID(sha1 字符串(更改为您知道的该分支的任何有效提交 ID(应该是您可以找到的最新提交 ID(。
然后运行以下命令:
git fetch
那你现在没事了。
对我来说,我通过在遥控器的 git 存储库上运行以下内容来解决它。
git fsck --full
错误:refs/heads/develop-xxx 的 MacBook Pro: 无效的 sha1 指针
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
然后我删除了文件:
.git/refs/heads/HEAD-xxx’s MacBook Pro
在本地 git 存储库中,我现在可以执行:
git fetch --all
git push remotename branchname