GIT "refs/heads/gh-pages does not point to a valid object!"

GIT "refs/heads/gh-pages does not point to a valid object!"

问:如何解决以下错误?

    error: refs/heads/gh-pages does not point to a valid object!
    error: refs/remotes/origin/gh-pages does not point to a valid object!
    error: refs/stash does not point to a valid object!

git statusgit log 都工作正常

来源

我删除了以下文件以释放一些 space 因为它是一个巨大的 2GB 因为我认为它是我提交并尝试过的巨大 2GB 文件的一部分用 bfg 删除。我以为这是它的最后踪迹。

rm ./.git/objects/pack/pack-bec4156621c0ce105abeedad0878eedf59f10a31.pack

调试

使用 $GIT_TRACE=1 git pull 我得到了下面的输出,但我担心所做的更改可能会影响我的实际存储库内容。

15:09:45.684046 git.c:344               trace: built-in: git 'pull'
15:09:45.684942 run-command.c:334       trace: run_command: 'fetch' '--update-head-ok'
15:09:45.685426 exec_cmd.c:189          trace: exec: 'git' 'fetch' '--update-head-ok'
15:09:45.687727 git.c:344               trace: built-in: git 'fetch' '--update-head-ok'
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/stash does not point to a valid object!
15:09:45.692615 run-command.c:334       trace: run_command: 'git-remote-https' 'origin' 'https://github.com/flipdazed/Hybrid-Monte-Carlo.git'
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/stash does not point to a valid object!
15:09:46.658813 run-command.c:334       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
15:09:46.667707 run-command.c:334       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all'
15:09:46.668230 exec_cmd.c:189          trace: exec: 'git' 'rev-list' '--objects' '--stdin' '--not' '--all'
15:09:46.670683 git.c:344               trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all'
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/stash does not point to a valid object!
error: refs/heads/gh-pages does not point to a valid object!
error: refs/remotes/origin/gh-pages does not point to a valid object!
error: refs/stash does not point to a valid object!
15:09:46.674636 run-command.c:334       trace: run_command: 'gc' '--auto'
15:09:46.675101 exec_cmd.c:189          trace: exec: 'git' 'gc' '--auto'
15:09:46.677382 git.c:344               trace: built-in: git 'gc' '--auto'
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

你不应该删除任何 .pack 文件,它打包了你的很多提交。由于它已被删除,您丢失了许多提交,包括 refs/heads/gh-pages 指向的提交。如果您已将所有本地引用推送到另一个存储库,则可以取回它们或制作另一个克隆。但如果你还没有,也许你需要一些工具来从你的硬盘恢复被删除的数据。

通常Git在.git/objects/中存储松散对象(包括committreeblobannotated tag)。例如,如果有一个 sha1 为 1daa24d58e28ee48365d594e90ebb215ddd47809 的提交,您可以找到它作为 .git/objects/1d/aa24d58e28ee48365d594e90ebb215ddd47809。为了进一步保存 space,Git 将它们打包成 .pack.idx 并通过 git gc 将它们存储在 .git/objects/pack 中,即 运行 手动或自动。

参考:Git Internals