pedalpete
pedalpete

Reputation: 21566

create a new git repository after deleting an old one

I'm not sure what has happened to my git repository, but for two days, every time I make a commit it starts deleting files seemingly at random, and then not letting me merge because of conflicts etc. etc.

I've got the app back to a usable state now, and I thought I would just delete the .git file and run git init to create a new git.

When I do that, I get

 git init
fatal: cannot copy '/usr/share/git-core/templates/hooks/commit-msg.sample' to '/media/sf_Ruby192/myapp/.git/hooks/commit-msg.sample': Operation not permitted

--------------- UPDATE of LS -al

This is running in virtual box ubuntu on Windows host. The strange thing is this has been running for about 7 months without issue, and then all of a sudden GIT started deleteing files and I figured my .git was corrupted tried to re-build it and ran into all these problems.

total 62
drwxrwx--- 1 root vboxsf 4096 2012-03-16 15:03 .
drwxrwx--- 1 root vboxsf 8192 2012-03-15 13:29 ..
drwxrwx--- 1 root vboxsf 4096 2012-02-20 06:43 app
drwxrwx--- 1 root vboxsf 4096 2012-03-16 09:45 config
-rwxrwx--- 1 root vboxsf  161 2011-12-27 05:31 config.ru
drwxrwx--- 1 root vboxsf 4096 2012-03-08 09:58 db
drwxrwx--- 1 root vboxsf    0 2011-12-27 05:31 doc
-rwxrwx--- 1 root vboxsf 1369 2012-02-27 07:23 Gemfile
-rwxrwx--- 1 root vboxsf 4374 2012-02-27 07:24 Gemfile.lock
-rwxrwx--- 1 root vboxsf   86 2012-02-22 13:21 .gitignore
drwxrwx--- 1 root vboxsf    0 2012-02-20 06:43 lib
drwxrwx--- 1 root vboxsf 4096 2012-02-22 08:50 log
drwxrwx--- 1 root vboxsf 4096 2012-03-18 09:02 public
-rwxrwx--- 1 root vboxsf  274 2011-12-27 05:31 Rakefile
-rwxrwx--- 1 root vboxsf 9386 2011-12-27 05:31 README
drwxrwx--- 1 root vboxsf    0 2012-02-27 07:16 redis
drwxrwx--- 1 root vboxsf 4096 2011-12-27 05:31 s
drwxrwx--- 1 root vboxsf    0 2011-12-27 05:31 script
drwxrwx--- 1 root vboxsf    0 2011-12-27 05:31 solr
-rwxrwx--- 1 root vboxsf    4 2012-02-20 06:43 sunspot-solr.pid
drwxrwx--- 1 root vboxsf 4096 2011-12-27 05:31 test
drwxrwx--- 1 root vboxsf 4096 2011-12-27 05:31 thin
drwxrwx--- 1 root vboxsf    0 2011-10-09 09:23 tmp
drwxrwx--- 1 root vboxsf    0 2011-12-27 05:31 vendor

------------------UPDATE-----------------------------

going through the steps recommended by Brian, there is a .git directory (which I new, and had renamed before running the initial git init. when i do an ls -l .git, I get

ls cannot access .git: No such file or directory

However, i can cd into the .git folder, but also can't run -ls from inside .git as I get

ls cannot access directory: Operation not permitted

any suggestions on how to get out of this hole??

Upvotes: 0

Views: 2404

Answers (3)

Fujiwara Takuya
Fujiwara Takuya

Reputation: 1

I also met this problem. The reason was disk full...

Upvotes: 0

Jeff
Jeff

Reputation: 1558

I had this problem myself. It turned out that the shell was holding on to some properties about the git repo that was deleted. After deleting I was getting the same fatal: cannot copy error. Closing the shell and opening a new one solved the problem. In a new shell I was able to init a new git repo. I have also had this problem when attempting to re-cloning a repo after deleting it. Starting a new shell solved the problem again.

Upvotes: 1

Brian Campbell
Brian Campbell

Reputation: 333206

To debug a problem with permissions, it is generally useful to check the permissions of the files in question: the source file, the destination file, and the destination directory.

Try ls -l /usr/share/git-core/templates/hooks/commit-msg.sample to determine the permissions on your commit-msg.sample template; if you don't have read permission, then you won't be able to read it (git init copies several template files into your git repository; if it can't read the source files, you will get an error).

Next, try checking out the permissions for the destination files. From your project directory, run ls -al. Check to see what the permissions are for . (the current directory). Do you have write permission for .? Is there already a .git directory? Do you have write permission for it? If there is already a .git directory, then do an ls -l in there. Is there already a hooks directory? Do you have write permission in it? Finally, see what happens if you manually try copying /usr/share/git-core/templates/hooks/commit-msg.sample to your .git/hooks directory. Do you get the same error?

It may be that following these steps will help you solve the problem yourself. If not, please put the output of those ls -l commands in your question, which will help us figure out what is going on.

Upvotes: 1

Related Questions