Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone of an old bare repository appears empty

Tags:

git

I'm trying to recover some files from a backup of an old, bare, git repository which was originally managed using Tortoise Git in Windows (if that makes any difference) but when I clone it on my Mac I get the message:

warning: You appear to have cloned an empty repository.

I understand this warning but I do not believe this repository is empty. I've been trying to learn more about the way git works but I don't seem to be getting anywhere, this is where I need your help.

Looking at the files in the "remote" (it's actually sitting on an external HDD) repository there are the following files/folders; what makes me think the repository is not actually empty is because the objects folder contains 161 sub folders, about 87MB of data:

remote repository folders

The contents of the master file is a checksum (I'm guessing) that (I think) points to the head of the master branch. However, running the command git branch -a returns nothing.

I also tried using gitk --all but that gives the error:

Error parsing revisions: unknown revision HEAD

I looked in to repairing a git repository and that lead me to try creating a new repo, copying the .pack files in and unpacking them with git unpack-objects < my.pack. This created a load of folders/files in the objects folder but still commands such as git branch and git checkout fail.

Can anyone suggest a way to get at the the files in the objects folder?

Some more info

Here's the command line output when I clone the project and then try to use it:

$ mkdir project
$ git init project
Initialized empty Git repository in /Users/tony/git/project/.git/
$ cd project/
$ git clone /Volumes/Backup/git/db/reporting
Cloning into 'reporting'...
warning: You appear to have cloned an empty repository.
done.
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
$ git branch -a
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

The result of the branch command is nothing and the checkout results in an error. I recognise the 'Initial commit' message as that's what I usually use when I first add files to a new repo.

I've tried unpacking the files in to a new repo, here's the command line output of that process:

$ mkdir unpack
$ git init unpack/
Initialized empty Git repository in /Users/tony/git/unpack/.git/
$ cd unpack/
$ git unpack-objects < /Volumes/Backup/git/db/reporting/objects/pack/pack-9e157880d61b9a9cecba012130de16cc71f898b5.pack
Unpacking objects: 100% (185/185), done.
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
$ git branch
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

The next thing I tried was to add a simple text file to the repo, this managed to reinstate the master branch:

$ pico readme
$ ls
readme
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    readme

nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git commit -m 'added a file'
[master (root-commit) 3ec34b9] added a file
 1 file changed, 1 insertion(+)
 create mode 100644 readme
$ git status
On branch master
nothing to commit, working directory clean
$ git branch
* master
$ git checkout master
Already on 'master'

The addition of a new file has enabled me to see the branch again but unfortunately I'm still unable to recover the files from the objects folder.

In response to Vorac's comment, here's the output when I don't create a repo first:

$ git clone /Volumes/Backup/git/db/reporting
Cloning into 'reporting'...
warning: You appear to have cloned an empty repository.
done.
$ ls
reporting
$ cd reporting/
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
$ git log
fatal: your current branch 'master' does not have any commits yet
$ git show
fatal: your current branch 'master' does not have any commits yet

The contents of the config file

[core]
    repositoryformatversion = 0
    filemode = false
    bare = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly

As suggested by Roman I ran the fsck command on a copy of the respoitory, here's the output:

$ git fsck --full
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
notice: No default references
like image 740
Tony Avatar asked Nov 09 '22 19:11

Tony


1 Answers

It looks like you have a double repository - your bare repository is a working copy of an empty non-bare repository. I don't know if your file manager shows hidden files, but you should look for a .git folder inside your bare repository folder (using ls -al, for example); also you can confirm this by running git status inside the bare repository - if I'm right, it will print something like the following:

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   HEAD
#   config
#   description
#   hooks/
#   info/
#   refs/
#
nothing added to commit but untracked files present (use "git add" to track)

If it is the case, you should separate the two - move .git folder somewhere (or just copy the repository and delete .git from copy).

like image 164
Roman Avatar answered Nov 15 '22 06:11

Roman