我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
当前回答
简单的读
Pro Git Book: 4.2 Git on the Server - get Git on a Server
归结起来是什么
$ git clone --bare my_project my_project.git
Cloning into bare repository 'my_project.git'...
done.
然后输入my_project。Git到服务器
主要是42号试图指出的答案。当然,人们可以重新发明轮子;-)
其他回答
我只是想推到网络路径上的存储库,但git不会让我这样做,除非该存储库被标记为裸。 我只需要改变它的配置:
git config --bool core.bare true
除非你想保持文件整洁,否则没必要乱动。
你的方法看起来可行;裸存储库的文件结构就是.git目录中的内容。但我不知道是否有文件被修改过,如果失败了,你可以这样做
git clone --bare /path/to/repo
您可能需要在不同的目录中执行此操作以避免名称冲突,然后您可以将其移回您想要的位置。您可能需要更改配置文件,以指向您的原始回购所在的位置。
我认为下面的链接会有帮助
GitFaq:如何使现有的非裸库变得裸?
$ mv repo/.git repo.git
$ git --git-dir=repo.git config core.bare true
$ rm -rf repo
我使用下面的脚本读取一个文本文件,其中包含我所有的SVN repo,并将它们转换为GIT,然后使用GIT clone——bare转换为一个裸露的GIT repo
#!/bin/bash
file="list.txt"
while IFS= read -r repo_name
do
printf '%s\n' "$repo_name"
sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name
sudo git clone --bare /programs/git/$repo_name $repo_name.git
sudo chown -R www-data:www-data $repo_name.git
sudo rm -rf $repo_name
done <"$file"
List.txt有这样的格式
repo1_name
repo2_name
users.txt有这个格式
(无作者)=罗杰斯王子<prince.rogers.nelson@payesley.park.org>
www-data是Apache web服务器用户,需要权限才能通过HTTP推送更改
简单的读
Pro Git Book: 4.2 Git on the Server - get Git on a Server
归结起来是什么
$ git clone --bare my_project my_project.git
Cloning into bare repository 'my_project.git'...
done.
然后输入my_project。Git到服务器
主要是42号试图指出的答案。当然,人们可以重新发明轮子;-)