git 传承老路

git inheritance old path

我从 git 开始。我草签了一个回购并做了第一次提交。为了与朋友一起工作,我将我的原始存储库(使用 --bare)克隆到一个可访问的位置,并开始与他一起处理该副本。所以我们的两个工作副本都是从后面的副本克隆而来的。在某些时候,我决定不再需要原始存储库并将其删除。现在我们的两个工作副本都显示了各种损坏的 links/objects/tree 错误,因为仍然有对原始 repo 的旧 location/path 的引用。我在哪里可以找到它或清理代码? 解释这是如何发生的会很好。在我们的理解中,所有 git 个实例都是独立的并且拥有完整的树。 (这就是使用 git 的意义所在)。

感谢您的帮助。 菲尔

p.s.: 我在克隆之前通过编辑 .git/config 删除了对旧存储库的引用。

编辑:

    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.

如果您不需要工作目录,您应该只复制裸存储库。您也不应该在 .git 目录中编辑任何内容,这不安全。

要更改遥控器,您可以使用这些命令:

  1. git remote -v 显示所有已配置遥控器的列表
  2. git remote rm [name] 删除 [name]
  3. 指定的远程
  4. git remote add [name] [path] 添加远程 [name] 和位置 [path],您可以按名称使用它,例如:git push [name] [branchname]
  5. git remote set-url [name] [newurl] 用新的 URL
  6. 更新 [name] 指定的遥控器

如果您使用-shared 克隆一个存储库,然后删除原始存储库,那您就不走运了;您只能通过从备份中恢复原件来恢复克隆。

故事的寓意:克隆存储库时永远不要使用“-shared”(唯一使用它的时间是当您的存储库占用了总磁盘的很大一部分时space,这在当今是很少见的情况。

引用 git 联机帮助页:

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.