【问题标题】:GIT refs/heads/master does not point to a valid objectGIT refs/heads/master 未指向有效对象
【发布时间】:2013-06-24 11:39:21
【问题描述】:

这是我的问题:

  1. 我创建了一个名为“项目”的新 git 存储库。里面有一些文件。
  2. 我使用以下代码克隆该存储库:

    git clone --bare project project.git

  3. Git 告诉我:
    Cloning into bare repository 'project.git'... done. error: refs/head/master does not point to a valid object!

  4. 我确实得到了一个名为 project.git 的目录,但如果我继续:

    • git init --bare --shared project.git
    • git clone project.git project2
  5. Git 告诉我:

    Cloning into 'project2'... warning: You appear to have cloned an empty repository. done.

所以我现在在克隆的存储库中没有文件:'project2'。我第一次遇到这个问题时,我试图像往常一样通过裸克隆共享一个现有的存储库。现在它发生在我创建的所有新存储库中。但是,如果我创建存储库,然后将其复制到我的另一台机器,然后在其上进行裸克隆,我没有问题。

有什么想法吗?

谢谢

更新:

问题只发生在网络驱动器上,而不是本地磁盘上。 C是我的本地盘,H是我的网盘:

本地 = 没问题:

$ cd c:/temp
$ mkdir foo; cd foo
$ git init
Initialized empty Git repository in c:/temp/foo/.git/
$ echo 'a' > a; git add a; git commit -m 'a'
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory.
[master (root-commit) f695c9d] a
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory.
 1 file changed, 1 insertion(+)
 create mode 100644 a
$ cd ..
$ git clone --bare foo foo.git
Cloning into bare repository 'foo.git'...
done.
$ ls foo.git/
HEAD  config  description  hooks  info  objects  packed-refs  refs

网盘=问题:

$ cd h:
$ mkdir foo; cd foo
$ git init
Initialized empty Git repository in h:/foo/.git/
$ echo 'a' > a; git add a; git commit -m 'a'
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory.
[master (root-commit) 5348b42] a
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory.
 1 file changed, 1 insertion(+)
 create mode 100644 a
$ cd ..
$ git clone --bare foo foo.git
Cloning into bare repository 'foo.git'...
done.
error: refs/heads/master does not point to a valid object!
$ ls foo.git/
HEAD  config  description  hooks  info  objects  packed-refs  refs

【问题讨论】:

  • 目前尚不清楚:原始 repo refs/head/master 是否指向有效提交?那是一个完美运行的回购协议,只会在克隆方面表现不佳吗?它有一个主分支吗?
  • 原始仓库指向一个有效的提交。即 SHA1 代码在提交和 refs/heads/master 之间匹配。我不确定如何判断这是否是有效的提交。回购似乎只在克隆时行为不端;我可以将它复制到另一台机器并在那里克隆它并且没有问题。不知道你的意思是:'它有一个主分支吗? repo 只有一个 master 分支。

标签: git


【解决方案1】:

这是否与您的结果不同:

$ mkdir foo; cd foo
$ git init
Initialized empty Git repository in /private/tmp/foo/.git/
$ echo 'a' > a; git add a; git commit -m 'a'
[master (root-commit) 235e657] a
 1 file changed, 1 insertion(+)
 create mode 100644 a
$ cd ..
$ git clone --bare foo foo.git
Cloning into bare repository 'foo.git'...
done.
$ ls foo.git/
HEAD        config      hooks/      objects/    refs/
branches/   description info/       packed-refs

如果是这样,我建议您的“项目”存储库有问题。例如,如果您从未在“项目”中提交过,则会发生这种情况:

$ mkdir bar; cd bar; git init
Initialized empty Git repository in /private/tmp/bar/.git/
$ echo 'a' > a; git add a
$ cd ..
$ git clone --bare bar bar.git
Cloning into bare repository 'bar.git'...
done.
warning: You appear to have cloned an empty repository.

【讨论】:

  • 是的,我也怀疑这一点,并且可能运行 fsck 和/或将内容获取到新的内容。
  • 我添加了一个更新。看来我只能在网盘上重新创建问题了。最初给我带来麻烦的 repo 实际上是在网络磁盘上。我把它从网盘上复制下来了,没有任何问题。正如您在我添加到初始消息中的输出中看到的那样;带有单个文本文件的新存储库会在网络磁盘上创建相同的错误,但不会在本地磁盘上。
【解决方案2】:

答案很简单,我也遇到了同样的问题。 GIT 不允许谷歌驱动器更新 \refs\heads\master ,因此您最终会在您已提交并推送的机器 A 和您尝试将其克隆到的另一台机器 B 上获得两个不同的参考代码。 .. 在你的机器 B 上手动更改参考代码,它工作得很好,但是,无论如何,每次提交后手动更新主文件是没有意义的 :)

【讨论】:

    猜你喜欢
    • 2022-08-15
    • 1970-01-01
    • 2019-10-26
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多