0

I am starting with git. I initialed a repo and did first commits. To work with a friend I cloned my original repository ( with --bare) to an accessible location and started working on that copy with him. So both of our working copies are cloned from the later one. On some point I decided that I don't need the original repo any more and deleted it. And now both of our working copy show all kinds of errors with broken links/objects/tree because there is still a reference towards the old location/path of the original repo. Where do I find that or clean up the code? An explanation how this happened would be nice. In our understanding all git instances are independent and hold the complete tree. (that was the point of using git).

Thanks for your help. Phil

p.s.: I removed the reference to the old repository from the bare one by editing .git/config before cloning.

edit:

    user@host:/work1/user/code/NIRVANA/TITVS> git remote -v
    origin  /work1/user/TITVS.git/ (fetch)                     #edit:this is the new repo
    origin  /work1/user/TITVS.git/ (push)                      #edit:this is the new repo
    user@host:/work1/user/code/NIRVANA/TITVS> git pull
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.    #edit:this is the OLD repo
    error: refs/remotes/origin/cleanning does not point to a valid object!
    error: refs/remotes/origin/phil_test does not point to a valid object!
    error: refs/remotes/origin/test does not point to a valid object!
    error: refs/remotes/origin/test2 does not point to a valid object!
    error: refs/tags/0.2.0 does not point to a valid object!
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.
    error: refs/heads/cleanning does not point to a valid object!
    error: refs/heads/phil_test does not point to a valid object!
    error: refs/heads/test does not point to a valid object!
    error: refs/heads/test2 does not point to a valid object!
    error: refs/tags/0.2.0 does not point to a valid object!
    error: refs/remotes/origin/cleanning does not point to a valid object!
    error: refs/remotes/origin/phil_test does not point to a valid object!
    error: refs/remotes/origin/test does not point to a valid object!
    error: refs/remotes/origin/test2 does not point to a valid object!
    error: refs/tags/0.2.0 does not point to a valid object!
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.
    error: refs/remotes/origin/cleanning does not point to a valid object!
    error: refs/remotes/origin/phil_test does not point to a valid object!
    error: refs/remotes/origin/test does not point to a valid object!
    error: refs/remotes/origin/test2 does not point to a valid object!
    error: refs/tags/0.2.0 does not point to a valid object!
    error: refs/remotes/origin/cleanning does not point to a valid object!
    error: refs/remotes/origin/phil_test does not point to a valid object!
    error: refs/remotes/origin/test does not point to a valid object!
    error: refs/remotes/origin/test2 does not point to a valid object!
    error: refs/tags/0.2.0 does not point to a valid object!
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.
    error: object directory /work1/user/TITVS/.git/objects does not exist; check .git/objects/info/alternates.
    Already up-to-date.
pmgast
  • 3
  • 4
  • Can you show us your errors ? – FrenchieTucker Jun 07 '16 at 16:46
  • Please give a specific example of an error message you are getting. If you use --shared when you set up your clones, deleting the original repository might have destroyed all your objects. – antlersoft Jun 07 '16 at 16:48
  • @antlersoft Tanks for the advice. I undid my changes and to config and used the commands given below to delete the repo but the problem is the same. Both repos (old and new) were --shared. – pmgast Jun 07 '16 at 19:58

2 Answers2

0

You should only copy bare repository if you don't need working directory. You also shouldn't edit anything in .git directory, it isn't safe.

To change remote you can use these commands:

  1. git remote -v shows list of all configured remotes
  2. git remote rm [name] removes remote specified by [name]
  3. git remote add [name] [path] adds remote with [name] and location [path], you can use it by name, for example: git push [name] [branchname]
  4. git remote set-url [name] [newurl] updates remote specified by [name] with new URL
0xCAFEBABE
  • 17
  • 1
  • 6
0

If you use -shared to clone a repository, and then delete the original repository, you are out of luck; you can only recover the clones by restoring the original from backup.

The moral of the story: Don't ever use "-shared" when cloning a repository (the only time to use it is if your repository takes up a large fraction of your total disk space, which is a rare situation nowadays).

To quote from the git manpage:

this is a possibly dangerous operation; do not use it unless you understand what it does. If you clone your repository using this option and then delete branches (or use any other Git command that makes any existing commit unreferenced) in the source repository, some objects may become unreferenced (or dangling). These objects may be removed by normal Git operations (such as git commit) which automatically call git gc --auto. (See git-gc(1).) If these objects are removed and were referenced by the cloned repository, then the cloned repository will become corrupt.

antlersoft
  • 14,636
  • 4
  • 35
  • 55
  • Ok... thanks for the heads-up. Is there a way to clean the new repository from the reference to the old one - if one does not care about the early commits (they are actually not so many)? – pmgast Jun 08 '16 at 08:44
  • @user544726 -- What you probably need to do is rm -rf the .git folder for your repository in your preferred non-bare source tree. (just the .git folder!)-- then your source tree is no longer tied to git. Then you act as though you are starting a new Git repository for an existing code base: run git init in the top folder; git add .; git commit. Since you have two different repositories with this problem, you need to do this in both. Then to sync the two repositories, you can set one as the remote of the other, and do a pull. – antlersoft Jun 08 '16 at 15:13
  • thx @antlersoft. Just starting new is however not a real fix for me. I was more hoping on help in the direction of the links below. I think it should be possible to clean the repo up. However I it is not worth searching for a solution any longer for my small repo. People with similar problems could look here: https://rewoo.wordpress.com/2012/02/14/recover-a-corrupt-git-bare-repository/ or search for "rebuilding git tree" or "recover corrupted repository". Did not worked for me though... – pmgast Jun 09 '16 at 07:40