添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I just came back to a repo I haven't touched in a couple of months and it's giving me strange issues.

Here are the results of a number of actions:

>>> git status
[Works as expected] On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  deleted:    app/views/steps/_self_service_code.html.erb
no changes added to commit (use "git add" and/or "git commit -a")
>>> git fsck --name-objects
Checking object directories: 100% (256/256), done.
Checking objects: 100% (11080/11080), done.
broken link from    tree 13f6a8bd586b1d5a80a3e67610fc1103fdd827ad (HEAD@{1595970321}^:app/)
              to    tree 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb (HEAD@{1595970321}^:app/views/)
missing tree 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb (HEAD@{1595970321}^:app/views/)
missing blob 9241fc61b7d8ede2f9c1081d97db7f4ae2dd81a7 (:app/views/steps/_self_service_code.html.erb)
>>> git restore app/views/steps/_self_service_code.html.erb
error: unable to read sha1 file of app/views/steps/_self_service_code.html.erb (9241fc61b7d8ede2f9c1081d97db7f4ae2dd81a7)
>>> git log --raw --all --full-history | grep 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb
fatal: unable to read tree 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb
>>> git log --raw --all --full-history | grep 9241fc61b7d8ede2f9c1081d97db7f4ae2dd81a7
fatal: unable to read tree 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb

I've tried everything I've read about online, including pulling from a Heroku repo and running 'First Aid' on my disk (it's a mac recently upgraded to Catalina from High Sierra). Nothing has fixed these issues so far.

Git version 2.28.0.

Is this an added worktree (from git worktree add)? Did you have Git 2.14 or earlier installed for a while, while using it? I've seen the pre-Git-2.15 bug in action here. Separately: HEAD@{1595970321}: that number in braces seems ridiculously huge; just how big is this HEAD reflog? – torek Sep 27, 2020 at 8:47 @torek It's not an added worktree - the repo has been one since the beginning. I was running an earlier version (not sure what version it was) for most of the time developing this repo. – sscirrus Sep 28, 2020 at 7:01 @DarekKay Cloning the app does work but I lose all my stashes and branches - it's not really a workable solution as-is. – sscirrus Sep 28, 2020 at 7:21

I have reproduced the issue. I've created a new repository and ran git ls-tree master:

$ git ls-tree master
100644 blob 5cca282c0449f01cf317c3b4b7ed9f7d65125095    file-31e422aa.txt
100644 blob 03a9272a34f3085006cab8d7f1d6a45225a95a75    file-981ec394.txt
100644 blob 12c194b0694b456102f3ceaec027606b3b0b3edd    file-bf32de9c.txt
100644 blob 45aa64b2dfa1d0647be0d776c810eb493e882b23    file-f46b47e4.txt
040000 tree e560d2adfdbb678d625ca5de6f20abbc929f7092    moo

I deleted the file .git/objects/e5/60d2adfdbb678d625ca5de6f20abbc929f7092 and ran the same command as you did:

$ git fsck --name-objects
Checking object directories: 100% (256/256), done.
error: e560d2adfdbb678d625ca5de6f20abbc929f7092: invalid sha1 pointer in cache-tree
broken link from    tree d0f8939f8d20cf252c1dd584526bcc6d7c3090e8 (:)
              to    tree e560d2adfdbb678d625ca5de6f20abbc929f7092 (:moo/)
missing tree e560d2adfdbb678d625ca5de6f20abbc929f7092 (:moo/)

As cloning the project solves your issue, it seems that the mentioned git objects are missing/corrupt in your .git/objects folder.

Option 1: Move your branches/stashes to your cloned repository.

Option 2: Move the broken git objects from your cloned repository into your broken repository.

Option 2 should work just fine. You can either move only the two objects mentioned in your CLI output or just copy&paste the entire .git/objects folder and merge (not overwrite!) it with your broken repository's .git/objects content. In any way, I suggest creating a full copy of your current broken repository before you attempt to solve the issue.

Note: be aware of the folder structure of your .git/objects folder. It contains two-char folders, where the two characters stand for the beginning of your object hash. So for example, your broken 9916bab22f21c3e8d77a0c4bb2e633ec26e45edb tree will be in .git/objects/99/16bab22f21c3e8d77a0c4bb2e633ec26e45edb of your cloned repository (and missing or corrupt in your broken repository).

It took a little more work because the Heroku repo didn't include the .git/objects files. Instead, I used Time Machine to go back to a version that had those files and selectively moved them into a copy of the latest repo. This seems to have worked. Thank you very much for your help Derek! +1 – sscirrus Sep 28, 2020 at 23:01

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.