Repair a broken git repo - how to have a fresh start

帅比萌擦擦* 提交于 2019-12-09 10:38:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5859569/repair-a-broken-git-repo-how-to-have-a-fresh-start

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!