获取本地git到新的github存储库时出错。

6

-- 编辑 -- 最终我将所有文件复制到另一个文件夹中并从那里推送。但是没有提交历史记录。:(

谢谢回复。

-- /EDIT --

我刚接触git。 对于我的html5应用程序,我使用aptana的html5模板,它会为你安装一个git存储库。很好。 现在,在开发我的应用程序几周之后,我想将其推送到GitHub上。我在那里创建了一个新的存储库。

现在当我尝试从shell或tortoisegit推送到GitHub时,所有文件上传后我遇到错误:

$ git push -u origin master
...
remote: error: unable to find b4587434...<snip>...c701 (probably a checksum)
remote: fatal: objet of unexpected type
error: unpack failed: index-pack abnormal exit 
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'https://github.com/<user>/<project>.git'

我一直在寻找解决方案,但还没有找到合适的。以下是一些我尝试过却没有帮助的方法:

  • 我将原始文件名更改为其他名称。
  • 我在Github上创建了另一个存储库。
  • "git status" 确认我没有任何提交内容。

请帮忙解答,Git花费了这么多时间去解决本应简单的问题,这真的很令人沮丧。:(


git fsck --full 会输出什么信息? - knittl
检查对象目录:100% 检查对象:100% - winkbrace
我在CentOS 7上遇到了同样的问题。我的Git版本是1.8,在将Git更新为2.17后,错误消失了。 - bdurand
3个回答

5
我想复制Twbs bootstrap,但是遇到了一个错误,我的问题是我使用--depth=1克隆了repo。我重新克隆了没有使用--depth=参数的repo,并按照以下步骤成功地完成了操作:
  1. git clone --bare https://github.com/twbs/bootstrap.git
  2. cd bootstrap.git
  3. git push --mirror git@github.com:yourusername/your-repo-name.git
  4. cd ../ && rm -rf bootstrap.git
  5. git clone git@github.com:yourusername/your-repo-name.git
  6. cd your-repo-name
  7. git remote add twbs https://github.com/twbs/bootstrap.git
现在你可以使用git push origin master推送到自己版本的repo,如果你想从原始repo拉取更改,只需简单执行git pull twbs master即可。
更多信息,请访问https://help.github.com/articles/duplicating-a-repository/

0

注意:至少在git 2.0.1(2014年6月25日)版本中,错误信息可能更加具体。

请参见提交77583e7Jeff King (peff)

index-pack:区分缺失对象和类型错误

当我们获取一个不包含我们期望接收的对象的包时,我们会收到如下错误:

$ git init --bare tmp.git && cd tmp.git
$ git fetch ../parent.git
[...]
error: Could not read 964953ec7bcc0245cb1d0db4095455edd21a2f2e
fatal: Failed to traverse parents of commit b8247b40caf6704fe52736cdece6d6aae87471aa
error: ../parent.git did not send all necessary objects

这个来自于check_everything_connected rev-list。如果我们尝试克隆相同的仓库(而不是使用fetch),我们最终会使用index-pack--check-self-contained-and-connected选项,该选项会产生如下输出:
$ git clone --no-local --bare parent.git tmp.git
[...]
fatal: object of unexpected type
fatal: index-pack failed

不仅缺少sha1,而且这是一个误导性的信息。
问题不在于类型,而是缺少对象;我们之所以没有注意到这个区别,是因为我们只是比较OBJ_BAD != OBJ_BLOB
让我们为这种情况提供不同的消息:
$ git clone --no-local --bare parent.git tmp.git
fatal: did not receive expected object 6b00a8c61ed379d5f925a72c1987c9c52129d364
fatal: index-pack failed

顺便说一下,让我们也将真正的类型不匹配错误改进为如下形式。
fatal: object 6b00a8c61ed379d5f925a72c1987c9c52129d364: expected type blob, got tree

嗨,你找到了正确的解决方案吗? - user1938143
我有同样的问题。 - user1938143
@user1938143 我没有直接的解决方案,只能通过更精确的错误信息提供更好的诊断。 - VonC

0

所以你可以尝试一下这个:

  1. 前往github.com/THE_REPO_YOU_MADE
  2. 复制位于您的repo顶部的SSH URL
  3. 删除任何旧的origin remotes

    git remote
    git remote rm origin
    
  4. 创建一个名为“origin”(或您想要的任何名称)的github remote

    git remote add origin git@github.com:USER_NAME/REPO_NAME.git
    
  5. 将您的文件推送到刚添加的remote

    git push remote origin master
    

这些步骤假设您已经完成:

git init # creates a local repo
git add . # adds all files in the current directory
git commit -m "init commit" #commits your init

我知道这些步骤非常基础,可能无法解决您遇到的错误,但这些步骤:

另外一个尝试的方法是检查是否在存储库内有一个存储库。 这是我的学生有时会遇到的问题。它会导致一些推送错误以及权限问题。


谢谢您的回复。不幸的是,我已经尝试过了,结果还是一样。:( - winkbrace

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接