如何修复从树到树的 git 错误断开的链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36876512/
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
How to fix git error broken link from tree to tree?
提问by SSM89
I got a transaction interrupted and when I try again I was having error with objects that were empty or corrupted, following another question I delete all the empty files and when I run
我的事务中断了,当我再次尝试时,我的对象为空或已损坏时出错,在另一个问题之后,我删除了所有空文件,当我运行时
git fsck --full
I got this error
我收到这个错误
Checking object directories: 100% (256/256), done.
Checking objects: 100% (48774/48774), done.
error: d193ccbc48a30e8961e9a2515a708e228d5ea16d: invalid sha1 pointer in cache-tree
error: df084ac4214f1a981481b40080428950865a6b31: invalid sha1 pointer in cache-tree
broken link from tree 4bf4869299b294be9dee4ecdcb45d2c204ce623b
to tree df084ac4214f1a981481b40080428950865a6b31
broken link from tree 4bf4869299b294be9dee4ecdcb45d2c204ce623b
to tree d193ccbc48a30e8961e9a2515a708e228d5ea16d
missing tree df084ac4214f1a981481b40080428950865a6b31
missing blob a632281618ca6895282031732d28397c18038e35
missing tree d193ccbc48a30e8961e9a2515a708e228d5ea16d
missing blob 70aa143b05d1d7560e22f61fb737a1cab4ff74c6
missing blob c21c0545e08f5cac86ce4dde103708a1642f23fb
missing blob 9f341b8a9fcd26af3c44337ee121e2d6f6814088
missing blob 396aaf36f602018f88ce985df85e73a71dea6f14
missing blob 87b9d1933d37cc9eb7618c7984439e3c2e685a11
And know I don't know how could I fix this problem.
并且知道我不知道如何解决这个问题。
采纳答案by VonC
With Git 2.10 (Q3 2016), you can know more about the origin of those broken links.
使用 Git 2.10(2016 年第三季度),您可以更多地了解这些断开链接的来源。
git fsck --name-objects
See commit 90cf590, commit 1cd772c, commit 7b35efd, commit 993a21b(17 Jul 2016) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
--in commit 9db3979, 25 Jul 2016)
请参阅Johannes Schindelin ( ) 的commit 90cf590、commit 1cd772c、commit 7b35efd、commit 993a21b(2016 年 7 月 17 日)。(由Junio C Hamano合并-- --在提交 9db3979 中,2016 年 7 月 25 日)dscho
gitster
fsck
: optionally show more helpful info for broken linksWhen reporting broken links between commits/trees/blobs, it would be quite helpful at times if the user would be told how the object is supposed to be reachable.
With the new
--name-objects
option,git-fsck
will try to do exactly that:
name the objects in a way that shows how they are reachable.For example, when some reflog got corrupted and a blob is missing that should not be, the user might want to remove the corresponding reflog entry.
This option helps them find that entry:git fsck --name-objects
will now report something like this:
fsck
: 可选地显示断开链接的更多有用信息在报告提交/树/blob 之间的断开链接时,如果告诉用户应该如何访问对象,有时会很有帮助。
使用新
--name-objects
选项,git-fsck
将尝试做到这一点:
以显示对象如何可达的方式命名对象。例如,当某些 reflog 损坏并且丢失了不应该丢失的 blob 时,用户可能希望删除相应的 reflog 条目。
此选项可帮助他们找到该条目:git fsck --name-objects
现在将报告如下内容:
broken link from tree b5eb6ff... (refs/stash@{<date>}~37:)
to blob ec5cf80...
If those broken links don't come from a local stash but a remote repo, fetching those pack objects can then solve the situation.
See also "How to recover Git objects damaged by hard disk failure?".
如果这些断开的链接不是来自本地存储而是来自远程存储库,那么获取这些包对象就可以解决这种情况。
另请参阅“如何恢复因硬盘故障损坏的 Git 对象?”。
回答by Tim Nafziger
What worked for me to fix this "broken link" error was the answer from sehelisted here in response to a question about how to fix an unable to find error:
对我来说修复这个“断开的链接”错误的方法是这里列出的sehe的答案,用于回答有关如何修复无法找到的错误的问题:
Like Adam said, recover the object from another repository/clone.
- On a 'complete' git database:
git cat-file -p a47058d09b4ca436d65609758a9dba52235a75bd > tempfile
- and on the receiving end:
git hash-object -w tempfile
就像亚当说的,从另一个存储库/克隆中恢复对象。
- 在“完整”的 git 数据库上:
git cat-file -p a47058d09b4ca436d65609758a9dba52235a75bd > 临时文件
- 在接收端:
git hash-object -w 临时文件
One important addition would be that between step 1 and 2, it is important to directly transfer the file from one location to the other. In my experience, it didn't work to move the tempfile using GIT push and pull.
一个重要的补充是在步骤 1 和 2 之间,将文件从一个位置直接传输到另一个位置很重要。根据我的经验,使用 GIT 推拉移动临时文件是行不通的。
回答by CodeWizard
git gc --aggressive
will cleanup unnecessary files and optimize the local repository.
git gc --aggressive
将清理不必要的文件并优化本地存储库。
You can verify that the problem is fixed with the git fsck --full
您可以使用以下命令验证问题是否已解决 git fsck --full