问题
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,
- have backups
- git clean -dfx .
- mv .git /tmp/_git.backup
- git init
- git add .
- 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