我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
我如何将一个“正常”的Git存储库转换为一个裸库?
主要的区别似乎是:
在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据
当前回答
除非您特别想要或需要在文件系统上摆弄比特,否则创建一个非裸库的裸版本真的非常简单(在这里的其他几篇文章中提到过)。它是git核心功能的一部分:
Git clone——bare existing_repo_path bare_repo_path
其他回答
下面是一个小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消息,并且不会发生文件系统更改。
首先,备份你现有的回购:
(a) mkdir backup
(b) cd backup
(c) git clone non_bare_repo
其次,运行以下命令:
git clone --bare -l non_bare_repo new_bare_repo
简单的读
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推送更改
用于执行上述所有操作的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)