gpt4 book ai didi

git - 从 git repo 中删除 '.git' 目录?

转载 作者:IT王子 更新时间:2023-10-29 01:18:56 27 4
gpt4 key购买 nike

我正在尝试将 git 存储库从 Kiln 迁移到 Github。我可以很好地添加新 Remote ,但是当我尝试将 master 推送到新 Remote 时,出现以下错误:

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'

提交 a9ee490ac00987835de30bdbc851da5e8d45d28b 包含以下文件:

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

显然过去有人使用 hg checkin 子目录中的完整 git 存储库。

我想完全删除该目录,但无法从 git 历史记录中删除该文件。

pushing a git repo fails with error: contains '.git'中的答案没有帮助,因为我将 repo 作为 git repo,而不是 mercurial。

我尝试了 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 知识的极限。谁能帮忙?

最佳答案

使用 BFG Repo-Cleaner ,一个更简单、更快速的 git-filter-branch 替代方案,专门用于从 Git 历史记录中删除文件。

请仔细按照此处的步骤操作:https://rtyley.github.io/bfg-repo-cleaner/#usage - 但核心部分就是这样:下载 BFG jar (需要 Java 8 或更高版本)并运行此命令:

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

将扫描您的整个存储库历史记录,并删除任何名为 .git 的文件或文件夹。我已经针对特制的 test repo 进行了测试包含一个 .git 文件夹,它工作得很好。

感谢 Michel Jouvin reminding me名为“.git”的文件在 Git 中也是非法的(Git 报告的错误消息并没有立即表明它们文件,而不是文件夹) ,我更新了这个答案以反射(reflect)这一点。

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

关于git - 从 git repo 中删除 '.git' 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16821649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com