修复损坏的 git 存储库 - 如何重新开始

发布于 2024-11-04 18:40:31 字数 468 浏览 1 评论 0原文

我是 git 的新手,对我的存储库的工作方式感到沮丧..或者在本例中不起作用..所以我从 git hub 中删除了它,删除了项目上的 git 文件夹并计划重新开始。

现在,当我尝试设置一个新的存储库时,我收到很多消息,例如:

warning: You appear to be on a branch yet to be born.
warning. Forcing checkout of HEAD

当我尝试运行第一次提交时,我看到:

error: invalid object 8bcb4b5fd612e3ad55fb07e4bed087c55afd0861
fatal: git-write-tree: error building trees

我运​​行了 git fsck 并发现我丢失了一堆 blob。

我怎样才能把石板擦干净然后再试一次呢?

I am somewhat of a newbie with git and was frustrated with how my repo was working.. or in this case not working.. so I deleted it off of git hub, deleted the git folder on the project and was planning to start fresh.

Now when i try and set up a fresh repo I am getting a lot of messages like :

warning: You appear to be on a branch yet to be born.
warning. Forcing checkout of HEAD

when I try and run the first commit I see :

error: invalid object 8bcb4b5fd612e3ad55fb07e4bed087c55afd0861
fatal: git-write-tree: error building trees

I ran git fsck and see that I am missing a bunch of blobs.

How can I just wipe the slate clean and try again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-11-11 18:40:31

好的,

  1. 有备份
  2. git clean -dfx 。
  3. mv .git /tmp/_git.backup
  4. git init
  5. git add 。
  6. git commit -m '在救援操作后重新启动存储库'

请注意 clean 步骤,该步骤可防止将许多以前未跟踪的内容添加到新存储库中。一个好的 .gitignore 对于防止类似的影响大有帮助。

如果需要,您可以手动迁移部分/全部旧配置,例如

 vim -d _git.backup/config .git/config

(或简单地复制它)

我不会详细讨论对潜在远程克隆/分支的影响:)

有多种方法可以协调类似的事情,但就目前而言,这似乎回答了你的问题。

Ok,

  1. have backups
  2. git clean -dfx .
  3. mv .git /tmp/_git.backup
  4. git init
  5. git add .
  6. git commit -m 'restart repo after rescue operation'

Note the clean step that prevents a lot of previously untracked stuff from being added to the new repo. A good .gitignore goes a long way to prevent effects like that.

If you want, you can manually migrate some/all of the old configuration, like

 vim -d _git.backup/config .git/config

(or simply copy it)

I'll not go into obvious details about impact on potential remote clones/branches :)

There are ways to reconcile things like that, but for now, this seems to answer your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文