4

I cloned a git repo some time ago. After cloning the repo it had source files and a .git folder. Now there is only the .git folder. Somehow the files were deleted (a long time back).

These are the contents of the .git folder:

Mic-Pro:sample.git mic$ ls
HEAD        config      config_     description hooks       info        objects     refs

git status says the directory is not a git repo. Given only that .git folder, is there any way to recover those files?

I can't clone the repo as its not available anymore

John Kaff
  • 1,905
  • 6
  • 18
  • 30
  • It sounds like the answer is pretty much as if you'd done an `rm -rf /` on your filesystem: 1) re-clone the repo (if it's still available), or 2) restore from backup (if you have one). – paulsm4 Dec 09 '15 at 22:26
  • Can you not re-clone the repo? Also, be sure you're running `git status` in the root of the repo directory tree, not inside the `.git` folder. – Nathaniel Ford Dec 09 '15 at 22:27
  • @paulsm4 can't clone the repo as its not available anymore – John Kaff Dec 09 '15 at 22:28
  • 1
    There's also a chance that *maybe* your .,git folder is intact, and maybe you can do `git clone file://////`: [Clone Git repo across local filesystem](http://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system-in-windows) – paulsm4 Dec 09 '15 at 22:31
  • If the .git folder is intact you might just be able to do `git checkout HEAD` in the parent directory. – Matthew Strawbridge Dec 09 '15 at 22:33
  • @paulsm4 thanks ur trick worked – John Kaff Dec 09 '15 at 22:38

2 Answers2

6

If you have not messed the files in the '.git' folder, this command should fix your problem :

git reset --hard HEAD
Philippe
  • 28,207
  • 6
  • 54
  • 78
1

Try this:

git init /tmp/recovery
cd /tmp/recovery
cp -r /path/to/broken/repo/.git/objects .git

More detailed: https://unix.stackexchange.com/questions/66891/how-to-recover-broken-partially-deleted-git-repository

Community
  • 1
  • 1
admix
  • 1,752
  • 3
  • 22
  • 27