2013-05-29 187 views
16

我正在嘗試將git庫從gilub遷移到Github。我可以添加新的遠程就好了,但是當我試圖推動主到新的遠程,我得到以下錯誤:從git repo中刪除'.git'目錄?

Counting objects: 8691, done. 
Delta compression using up to 8 threads. 
Compressing objects: 100% (3000/3000), done. 
remote: error: object a9ee490ac00987835de30bdbc851da5e8d45d28b:contains '.git' 
remote: fatal: Error in object 
error: pack-objects died of signal 13 
error: failed to push some refs to '[email protected]:Account/repo.git' 

提交a9ee490ac00987835de30bdbc851da5e8d45d28b中有下列文件:

.git/ 
CHANGELOG.md 
JSONKit.h 
JSONKit.m 
README.md 

很明顯,過去有人使用hg,在子目錄中檢查完整的git倉庫。

我想只殺死該目錄完全,但我有麻煩去除的提交歷史文件。

pushing a git repo fails with error: contains '.git'答案沒有幫助,因爲我的回購作爲一個git的回購,而不是一個善變的一個。

我試過git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch .git',但我得到的錯誤:

Rewrite 7dbd0970d6c79215d11994b4a9b8091b2e954cfb (326/442)error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/HEAD' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/config' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/description' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/applypatch-msg.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/commit-msg.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/post-update.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/pre-applypatch.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/pre-commit.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/pre-rebase.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/prepare-commit-msg.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/hooks/update.sample' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/index' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/info/exclude' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/logs/HEAD' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/logs/refs/heads/master' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/objects/pack/pack-43fac03d375df5c1e380c5e522ba6bcb9b4e1ec1.idx' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/objects/pack/pack-43fac03d375df5c1e380c5e522ba6bcb9b4e1ec1.pack' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/packed-refs' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/refs/heads/master' 
error: Invalid path 'Account/Libraries/ShareKit/Submodules/JSONKit/.git/refs/remotes/origin/HEAD' 

和歷史似乎並沒有被改變。我處於git知識的極限。誰能幫忙?

+0

是回購開源?你能分享一份嗎? –

+0

啊,沒必要分享有關回購的副本,我已經成功地構建一個Git倉庫用同一種不好的樹,我可以用於測試目的。 –

+0

[推一個git回購失敗,錯誤:包含'.git'](http://stackoverflow.com/questions/14728751/pushing-a-git-repo-fails-with-error-contains-git) –

回答

1

你有沒有試着用下面的命令?

git filter-branch --tree-filter 'rm -Rf .git' HEAD 

git filter-branch documentation表示,這將是比--index-filter慢,但它可以做的工作。

+1

不幸的是,我不認爲這種方法可以工作 - 運行測試回購我構建,這是我得到的輸出:$ git filter-branch --tree-filter'rm -Rf foo/.git'HEAD ..... 重寫6652877677cf01a7b668704134d5e8bb62bfe317(6/6)錯誤:路徑'foo/'git/folder/zero' 錯誤:無效路徑'foo/.git/hero' 錯誤:路徑'foo/.git/zero'無效 忽略路徑foo/.git /文件夾/零 忽略路徑foo /。 git/hero 忽略路徑foo/.git /零 警告:Ref'refs/heads/master'不變 –

+0

...所以它看起來像使用'git filter-branch --tree -filter'有問題,@dana遇到了問題。我認爲在這一點上使用BFG可能是一個更好的主意。 –

0

據我瞭解窯會讓你克隆版本庫無論是混帳或水銀這些天,所以克隆它善變,用mercurial filemap solution you already found推,作爲一個新的回購水銀回購窯,然後複製下來作爲飯桶。然後你會有一個git倉庫,你可以推送到github。

27

使用BFG Repo-Cleaner,以git-filter-branch更簡單,更快的替代方案專門針對提交歷史刪除文件而設計的。

仔細按照下列步驟進行:https://rtyley.github.io/bfg-repo-cleaner/#usage - 但核心的一點就是這一點:下載BFG jar(需要Java 6或以上),並運行此命令:

$ java -jar bfg.jar --delete-folders .git --delete-files .git --no-blob-protection my-repo.git 

你的整個倉庫的歷史將被掃描,並且任何名爲.git的文件或文件夾都將被刪除。我已經對包含.git文件夾的專門構建的test repo進行了測試,並且它工作得很好。

感謝米歇爾Jouvin爲reminding me文件名爲「git的」也是違法Git中(和Git的報告的錯誤消息不讓它立即明顯,他們文件,而不是文件夾) ,我已經更新了這個答案以反映這一點。

完全披露:我是BFG Repo-Cleaner的作者。

+0

我遇到了同樣的問題,而且這個解決方案對我來說是個竅門。 –

+1

謝謝!我也有同樣的問題,這也挽救了我的生命。如果我能,我會把這個標記爲正確的答案。 –

+1

我嘗試了git filter-branch的方法,但它不起作用,但是使用bfg回購清潔工像魅力一樣工作。謝謝! – omarshammas