2016-06-07 122 views
0

我开始与git。我草签了一个回购协议,并首先提交了。为了和朋友一起工作,我将我的原始存储库(使用--bare)克隆到可访问的位置,并开始与他一起处理该副本。所以我们的两份工作拷贝都是从后面的一份中克隆出来的。在某些时候,我决定不再需要原始回购并删除它。现在我们的工作副本都会显示各种链接/对象/树的错误,因为仍然会提供原始回购的旧位置/路径。我在哪里可以找到或清理代码? 解释如何发生这将是很好的。在我们的理解中,所有的git实例都是独立的,并持有完整的树。 (这是使用git的要点)。git继承旧路径

感谢您的帮助。 菲尔

P.S。:我通过克隆前编辑的.git /配置除去从裸一个参考到老库。

编辑:

[email protected]:/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 
    [email protected]:/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. 
+0

你能告诉我们你的错误? – FrenchieTucker

+0

请给出您正在获取的错误消息的具体示例。如果在设置克隆时使用--shared,则删除原始存储库可能会销毁所有对象。 – antlersoft

+0

@antlersoft坦克的建议。我解开了我的更改,并配置并使用下面给出的命令来删除回购,但问题是相同的。回购(新旧)都是共享的。 – user544726

回答

0

如果使用-shared克隆库,然后删除原始资料库,你的运气了;您只能通过从备份还原原始文件来恢复克隆。

故事的寓意:克隆存储库时永远不要使用“共享”(使用它的唯一时间是如果您的存储库占用大部分磁盘空间,这是一种罕见的情况如今)。

要从git的手册页引证:

这是一种可能的危险操作;除非你明白它的作用,否则不要使用它。如果您在使用 此选项克隆你的资料库,然后删除分支(或使用任何其他的Git命令 使任何现有的承诺未引用的)源 库,一些对象可能会变得未引用(或悬挂)。 这些目的可以通过正常GIT中的操作(如GIT中 提交),其自动调用的git GC --auto被移除。 (见GIT-GC(1))。如果被去除 这些目的和由克隆 储存库被引用,则该克隆库将变得损坏。

+0

好的......谢谢你的提醒。有没有一种方法可以清除引用旧存储库的新存储库 - 如果不关心早期提交(它们实际上并不那么多)? – user544726

+0

@ user544726 - 您可能需要做的是在您首选的非裸源树中为您的存储库使用rm -rf .git文件夹。 (只是.git文件夹!) - 那么你的源码树不再与git绑定。然后你就像为一个现有的代码库启动一个新的Git仓库一样:在顶层文件夹中运行git init; git add。; git commit。由于您有两个不同的存储库,因此需要在两个存储库中执行此操作。然后要同步这两个存储库,可以将其中一个设置为另一个的远程位置,然后执行拉取操作。 – antlersoft

+0

thx @antlersoft。然而,刚开始新的对我来说不是一个真正的解决方案。我更希望在下面的链接方面提供帮助。我认为应该有可能清理回购。然而,我不值得寻找一个解决方案为我的小回购。有类似问题的人可以看这里:https://rewoo.wordpress.com/2012/02/14/recover-a-corrupt-git-bare-repository/或搜索“重建git树”或“恢复损坏的存储库” 。虽然没有为我工作... – user544726

0

如果你不需要工作目录时,才应复制的裸库。你也不应该在.git目录中编辑任何东西,这是不安全的。

要远程改变你可以使用这些命令:

  1. git remote -v示出所有配置的遥控器
  2. git remote rm [name]将删除远程由[NAME]
  3. git remote add [name] [path]与远程添加[名称]及位置[指定的列表例如:git push [name] [branchname]
  4. git remote set-url [name] [newurl]使用新URL更新由[name]指定的远程地址