Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

repository

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?

like image 601
Zac Avatar asked May 02 '11 16:05

Zac


1 Answers

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.

like image 150
sehe Avatar answered Sep 19 '22 08:09

sehe