Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recovering broken git repository

Tags:

git

My working git repository is broken, it lose track to all the files in it, i.e.

$ git log
fatal: bad default revision 'HEAD'  
$ git status  
... told me that all the files are new

However the .git directory does contain my objects.

$ du -sh .git
34M    .git
$ git count-objects
4151 objects, 32692 kilobytes
$ git --version
git version 1.6.0.4

The last thing I remember doing before it went wrong was creating (clone --mirror) a backup repository at an NFS-mounted server. However the backup repository cloned is broken the same way.

How can I restore my repository?

like image 402
Eyoka Avatar asked Oct 09 '09 18:10

Eyoka


People also ask

How do I restore a git repository?

In the top right corner of GitHub.com, click your profile photo, then click Your organizations. Next to the organization, click Settings. In the left sidebar, click Deleted repositories. Next to the repository you want to restore, click Restore.

How do I fix repository not found?

Fix 5 - Git - remote: Repository not found Just run the git remote update command which updates the local repo with the remote repo and its credentials. If this command is executed without any issues then your issue will be resolved.

What is fsck in git?

It stands for File System ChecK. The name is taken from the Unix fsck command, which is used to validate a file system.


1 Answers

Try to check if each of your files in .git/ are owned by current user.

I had the same problem, when realizing I made some commits with root user, and that created objects (under .git/objects) where belongig to root, trigering errors when running git as regular user.

This command solved the problem:

sudo chown jb:jb .git/ -R *
like image 126
Jb. Avatar answered Oct 16 '22 23:10

Jb.