从git repo中删除'.git'目录? [英] Removing '.git' directory from git repo?

查看:276
本文介绍了从git repo中删除'.git'目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个git repo从Kiln迁移到Github。我可以添加新的远程设备,但是当我尝试将主设备推送到新的远程设备时,出现以下错误:

 计数对象:8691,完成。 
使用多达8个线程的增量压缩。
压缩对象:100%(3000/3000),完成。
remote:error:object a9ee490ac00987835de30bdbc851da5e8d45d28b:包含'.git'
remote:致命错误:对象
错误:pack-objects死于信号13
错误:未能推送一些ref'git@github.com:Account / repo.git'

提交 a9ee490ac00987835de30bdbc851da5e8d45d28b 中包含以下文件:

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

显然,过去有人使用 hg ,在一个子目录中检查完整的git仓库。



我会喜欢只是完全杀死该目录,但无法从git历史记录中删除该文件。



推git回购失败,错误:contains'.git'没有帮助,因为我已经回购作为一个git回购,而不是一个漂亮的o ne。



我试过 git filter-branch --index-filter'git rm -r --cached --ignore-unmatch .git' ,但我得到的错误:

pre> Rewrite 7dbd0970d6c79215d11994b4a9b8091b2e954cfb(326/442)error:Invalid path' Account / Libraries / ShareKit / Submodules / JSONKit / .git / HEAD'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / config'
错误: Libraries / ShareKit / Submodules / JSONKit / .git / description'
error:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / applypatch-msg.sample'
error:Invalid路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / commit-msg.sample'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / post-update .sample'
错误:路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / pre-applypatch.sample'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKi t / .git / hooks / pre-commit.sample'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / pre-rebase.sample'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / prepare-commit-msg.sample'
错误:路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / hooks / update .sample'
错误:路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / index'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / info / exclude'
error:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / logs / HEAD'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / logs / refs / heads / master'
错误:路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / objects / pack / pack-43fac03d375df5c1e380c5e522ba6bcb9b4e1ec1.idx'
错误:无效路径'帐户/库/ ShareKit /子模块/ JSONKit / git的/对象/包/包,43fac03d375df5c1e380c5 '
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / packed-refs'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit /。 git / refs / heads / master'
错误:无效路径'Account / Libraries / ShareKit / Submodules / JSONKit / .git / refs / remotes / origin / HEAD'

和历史似乎没有改变。我处于git知识的极限。任何人都可以提供帮助吗?

解决方案

使用 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 将被删除。我已经针对特殊构建的 test repo 包含一个 .git 文件夹,它工作得很好。



感谢Michel Jouvin为提醒我那个名为'.git'的文件在Git中也是非法的(并且Git报告的错误消息并不会立即显示它们是文件,而不是文件夹),我已经更新了这个答案以反映这一点。



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


I'm trying to migrate a git repo from Kiln to Github. I can add the new remote just fine, but when I try to push master to the new remote, I get the following error:

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 'git@github.com:Account/repo.git'

Commit a9ee490ac00987835de30bdbc851da5e8d45d28b has the following files in it:

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

Obviously someone in the past, using hg, checked in a full git repo in a subdirectory.

I'd like to just kill that directory entirely, but am having trouble removing that file from the git history.

The answer in pushing a git repo fails with error: contains '.git' doesn't help, because I've the the repo as a git repo, not a mercurial one.

I tried git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch .git', but I get the error:

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'

and history doesn't seem to be changed. I'm at the limit of my git knowledge. Can anyone help?

解决方案

Use the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for removing files from Git history.

Carefully follow the steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage - but the core bit is just this: download the BFG jar (requires Java 6 or above) and run this command:

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

Your entire repository history will be scanned, and any file or folder named .git will be removed. I've tested this against a specially-constructed test repo containing a .git folder, and it worked just fine.

Thanks to Michel Jouvin for reminding me that files named '.git' are also illegal in Git (and the error message reported by Git doesn't make it immediately obvious that they are files, rather than folders), I've updated this answer to reflect that.

Full disclosure: I'm the author of the BFG Repo-Cleaner.

这篇关于从git repo中删除'.git'目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆