如何移除克隆仓库时Git LFS初始化的提示消息?
如何阻止GitHub Desktop克隆原Git LFS仓库时的初始化提示
问题描述
使用GitHub Desktop克隆曾使用过Git LFS的仓库时,会弹出以下提示:
This repository uses Git LFS. To contribute to it, Git LFS must first be initialized. Would you like to do so now? [path to repository]
该仓库已不再使用Git LFS,需要彻底消除这个提示。
已尝试的方法及问题
git-lfs migrate export迁移
执行官方推荐的迁移命令转换历史中的LFS指针:git lfs migrate export --everything --include='*' git push --force --all重新克隆后提示仍存在。
卸载仓库Git LFS
- 执行
git lfs uninstall - 尝试通过
git lfs ls-files查找LFS文件,无结果;对文件执行git rm --cached和git add无变更,提交无内容 - 检查
.gitattributes,无LFS相关条目
操作后问题未解决。
- 执行
BFG Repo-Cleaner尝试
用git ls-files | xargs du -sh查看文件大小,考虑用bfg --strip-blobs-bigger-than [size] [your-repo].git删除大文件,但历史中有需保留的大文件,且不确定能否移除LFS依赖,暂未执行。
解决方案
1. 清理本地仓库及全局的LFS配置
执行命令清除LFS相关配置:
# 清除本地仓库LFS配置 git config --unset-all lfs.url git config --unset-all lfs.fetchinclude git config --unset-all lfs.fetchexclude git config --unset-all lfs.pushinclude git config --unset-all lfs.pushexclude # 若全局无需LFS,可清除全局配置 git config --global --unset-all lfs.url
同时打开本地仓库的.git/config文件,手动删除所有[lfs]段落;检查全局配置文件(~/.gitconfig或%USERPROFILE%\.gitconfig),移除LFS相关内容。
2. 补全分支与标签的LFS迁移
git lfs migrate export --everything可能遗漏部分分支或标签,需逐个处理:
# 获取所有本地和远程分支 branches=$(git branch -a | grep -v HEAD | sed 's/remotes\/origin\///') # 遍历分支执行迁移 for branch in $branches; do git lfs migrate export --include='*' --ref=$branch done # 强制推送所有分支和标签 git push --force --all git push --force --tags
3. 删除远程仓库的LFS对象
登录仓库托管平台(如GitHub),进入仓库设置的LFS存储页面,删除所有已上传的LFS对象(确认不再需要后操作)。
4. 清理GitHub Desktop缓存
若以上操作后提示仍存在,清理缓存后重试:
- 关闭GitHub Desktop
- 删除对应系统的缓存目录:
- Windows:
%APPDATA%\GitHub Desktop\Cache - macOS:
~/Library/Caches/GitHub Desktop - Linux:
~/.cache/github-desktop
- Windows:
- 重新启动GitHub Desktop并克隆仓库。
内容的提问来源于stack exchange,提问作者Joshua Shew
相关产品推荐
相关产品推荐

