推送git repo失败并显示错误:包含'.git'

时间:2013-02-06 12:08:48

标签: git mercurial

我使用hg-fast-export工具将一些mercurial repos转换为git,虽然所有这些都转换得很好,但是当我推送回购时,会产生以下错误。

$ git remote add origin git@github.com:asdf/zxcv.git
$ git push -u origin master
Counting objects: 7840, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2817/2817), done.
error: object 324f9ca2aaae7b1d716db3fc31c02d391c1c2c16:contains '.git'
fatal: Error in object
error: pack-objects died of signal 13
error: failed to push some refs to 'git@github.com:asdf/zxcv.git'

“包含'.git'”错误包含非常广泛的术语,找不到任何文档,因此我尝试在原始仓库中搜索现有的'.git'文件夹,我做了。有一个subsubsub文件夹,其中包含我使用git rm删除的旧git存储库的实例,但问题仍然存在。

无论如何我可以把它推到github或新的清洁回购是唯一的选择吗?

任何帮助都表示赞赏。 谢谢!

2 个答案:

答案 0 :(得分:5)

您可以将convert命令与 filemap 一起使用,以从存储库中删除git repo。之后它将从历史记录中消失,并且存储库可以安全地导入到git。

示例:

$ echo "exclude path/to/.git" > my-filemap
$ hg convert --filemap my-filemap originalrepo newrepo

请注意,convert是一个捆绑的扩展程序,您首先需要在.hgrc中启用它,如下所示:

[extensions]
convert =

有关详细信息,请参阅hg help convert

答案 1 :(得分:0)

您尝试推送的更改集在其历史记录中包含.git,即使不在最新的更改集中,因此我认为您需要创建一个干净的回购。

然而,另一种选择可能是改变一些变更集。提供您想要推送的内容包含添加无关.git之前的更改集,并且您不介意丢失一些历史详细信息,您可以rebase将它们放入一个变更集并尝试推送它。在理论上(!!),.git目录将被有效地“编辑”出历史记录。

这是一个例子(请注意,我不像Mercurial那样使用git,所以不知道这是否有效,或者我的命令是否有效,但它可以给你一个起点):

$ git log --oneline  
1234567 More changes
abcdefa made changes
a5b6482 Added .git sub-sub-sub-directory to repo!
dead123 More things

$ git rm sub-sub-sub/.git
$ git commit -m "Removed .git sub-sub-sub-directory"
$ git log --oneline  
beef456 Removed .git sub-sub-sub-directory
1234567 More changes
abcdefa made changes
a5b6482 Added .git sub-sub-sub-directory to repo!
dead123 More things

$ git rebase -i HEAD~4
... at this point you need to interactively specify what to do*
$ git log --oneline  
eeee987 Some new commit message that sums up the changes
dead123 More things

当我尝试这个时,变形集的列表“被压扁”出现在一个编辑器中,这与我看到的所有教程都不同 - 我想由于添加和删除文件的冲突。我将四个变更集中的三个的命令修改为“squash”而不是“pick”,它指示rebase-merge将变更集压缩到其父变量中。我基本上把所有的变更集都压成了一个。它似乎对我有用,其余的变更集都没有删除的文件。不管是否允许你推,我不知道。

当然,首先尝试克隆或其他东西。