我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
当前回答
下面是一个小BASH函数,您可以将它添加到基于UNIX的系统上的.bashrc或.profile中。一旦添加,shell要么重新启动,要么通过调用source ~/重新加载文件。配置文件或源代码~/.bashrc。
function gitToBare() {
if [ -d ".git" ]; then
DIR="`pwd`"
mv .git ..
rm -fr *
mv ../.git .
mv .git/* .
rmdir .git
git config --bool core.bare true
cd ..
mv "${DIR}" "${DIR}.git"
printf "[\x1b[32mSUCCESS\x1b[0m] Git repository converted to "
printf "bare and renamed to\n ${DIR}.git\n"
cd "${DIR}.git"
else
printf "[\x1b[31mFAILURE\x1b[0m] Cannot find a .git directory\n"
fi
}
一旦在包含.git目录的目录中调用,它将进行适当的更改以转换存储库。如果调用时不存在.git目录,则会出现FAILURE消息,并且不会发生文件系统更改。
其他回答
我已经看了答案,我是这么做的:
cd repos
mv .git repos.git
cd repos.git
git config --bool core.bare true # from another answer
cd ../
mv repos.git ../
cd ../
rm -rf repos/ # or delete using a file manager if you like
这将留下repos/。Git作为裸rest . Git
用于执行上述所有操作的onlineer:
for i in `ls -A .`; do if [ $i != ".git" ]; then rm -rf $i; fi; done; mv .git/* .; rm -rf .git; git config --bool core.bare true
(如果事情搞砸了,你又没有备份,可别怪我:P)
也请大家考虑使用
git clone --mirror path_to_source_repository path_to_bare_repository
从文档中可以看到:
设置源存储库的镜像。这意味着——裸露。与——bare相比,——mirror不仅将源的本地分支映射到目标的本地分支,它还映射所有的引用(包括远程跟踪分支,notes等),并设置一个refspec配置,以便所有这些引用都被目标库中的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号试图指出的答案。当然,人们可以重新发明轮子;-)
我使用下面的脚本读取一个文本文件,其中包含我所有的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推送更改