我有一个简单的git存储库,但需要通过ssh访问和浏览其内容(在文件管理器中,如用户体验).
我想我可以克隆它:
git clone -l <path_to_bare_repo> <new_normal_repo>
Run Code Online (Sandbox Code Playgroud)
但是,我的存储库大小约为20GB,我没有空间来复制它.有没有办法将裸存储库就地转换为最终的工作副本?
sim*_*ont 103
注意:我在一个非常简单的 1-commit存储库上测试了这个.仔细检查一下,阅读手册页,并且在按照您在StackOverflow上找到的建议之前,总是很高兴您已经备份了.(你做备份,对吧?)
要将--bare存储库转换为非裸存储:
.git在存储库的顶级创建一个文件夹.HEAD branches config description hooks info objects refs等)移动到.git刚刚创建的内容中.git config --local --bool core.bare false以将本地git-repository转换为非裸.master(或您的主分支机构),并且所有文件都被删除并且删除被暂存.这很正常.只需手动结账master,或做一个git reset --hard,你就完成了..git/config文件中添加行fetch = +refs/heads/*:refs/remotes/origin/*后url = <...>的[remote "origin"]部分.否则git fetch将不会看到origin/master和其他原产地的分支.这些步骤与这个问题的方向相反,"git-convert normal to bare repository" - 特别注意这个答案,其中指出上述步骤(我认为,任一方向)与做a 不同git-clone.不过,不确定这是否与您相关,但您git clone在问题中提到过.
Von*_*onC 16
我有一个略有不同的情况:
解:
.gitdir中克隆该内容中的裸仓库:git clone --bare https://github.com/user/project .gitgit config --local --bool core.bare false.git 裸的 repo不包含文件' index'.)git reset HEAD -- ..git/index.我已经有效地将一个裸露的回购变成了一个非裸露的回购,同时保留了我之前获得的内容.我多年来一直使用
的完整脚本涉及以下步骤:
cd /path/to/current/worktree
# That creates a .git directly at the right place
git clone --bare /url/of/repo .git
# restore the link between the local repo and its upstream remote repo
git config --local --bool core.bare false
git config --local remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch origin
git branch -u origin/master master
# reset the index (not the working tree)
git reset HEAD -- .
Run Code Online (Sandbox Code Playgroud)
但我去侦察一下接受的解决方案(与有益git reset补充步骤由ADTC)更简单.
fuz*_*Tew 11
简化和组合答案中的信息:
有两个区别使得裸仓库与普通的.git文件夹不同:
所以,你可以简单地将你的裸仓库移动到新文件夹的.git子文件夹,
mkdir clone
mv bare.git clone/.git
Run Code Online (Sandbox Code Playgroud)
改变core.bare:
cd clone
git config --local --bool core.bare false
Run Code Online (Sandbox Code Playgroud)
并生成索引文件和工作树:
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
Run Code Online (Sandbox Code Playgroud)
我建议git fetch而不是git push生成文件,以防它被意外键入错误的位置.
如果磁盘空间不足,则通过转换为普通存储库来扩展工作树将是一个问题,但您可以浏览裸存储库的内容而无需转换它.用于git cat-file -p <commit-sha>任何提交以查看它所引用的树.使用git cat-file -p <blob-sha>查看由BLOB引用的文件的内容.使用git show <sha>:path其中啥是提交或一棵树看Blob的内容的路径.
原始海报的问题是没有足够的空间以简单的方式做事.对于那些有足够空间的人来说,答案要简单得多:
git clone foo.git foo
Run Code Online (Sandbox Code Playgroud)
cd 进入裸回购并做
git config core.bare false
git reset --hard
Run Code Online (Sandbox Code Playgroud)
git clone X.git X
Run Code Online (Sandbox Code Playgroud)
(会给你一个名为 X 的常规 git repo)