Friday, September 7, 2012

Git re-initialize fix after corruption

Today, a project directory was somehow corrupted and cannot add new file nor commit modified files to the local repository. 
With error like these:

$ git add .
error: insufficient permission for adding an object to repository database .git/objects

error: clickthecity.rb: failed to insert into database
error: unable to index file clickthecity.rb
fatal: updating files failed


It's found that some directories under .git/objects were owned by root.  Maybe some commits were done under the root access.
After a few tries in vein, I do just re-initialize the local git repository.

$ sudo rm -rf .git
$ git init
$ git add .
$ git remote add origin [your_server]:[dir]
$ git commit -a -m "..."
$ git pull origin master


And do some code merging.

$ git push origin master

Done.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.