我如何将一个“正常”的Git存储库转换为一个裸库?

主要的区别似乎是:

在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.git)包含实际的存储库数据


当前回答

以下是我认为最安全、最简单的方法。这里没有没有上面说过的。我只是想看到一个答案,显示一个安全的一步一步的程序。您从想要使其为空的存储库(repo)中启动一个文件夹。我采用了上面暗示的约定,即裸存储库文件夹具有.git扩展名。

(1) Backup, just in case.
    (a) > mkdir backup
    (b) > cd backup
    (c) > git clone ../repo
(2) Make it bare, then move it
    (a) > cd ../repo
    (b) > git config --bool core.bare true
    (c) > mv .git ../repo.git
(3) Confirm the bare repository works (optional, since we have a backup)
    (a) > cd ..
    (b) > mkdir test
    (c) > cd test
    (d) > git clone ../repo.git
(4) Clean up
    (a) > rm -Rf repo
    (b) (optional) > rm -Rf backup/repo
    (c) (optional) > rm -Rf test/repo

其他回答

删除文件和移动.git目录的方法是不干净的,没有使用“git”方法来做一些应该简单的事情。这是我发现的将正常回购转换为裸回购的最干净的方法。

第一个克隆/path/to/normal/repo到一个名为repo.git的裸repo

git clone --bare /path/to/normal/repo

接下来删除指向/path/to/normal/repo的原点

cd repo.git
git remote rm origin

最后,您可以删除原来的回购。你可以重命名repo。在这一点上,Git的回购,但标准约定,以表示一个Git存储库是什么。git,所以我个人会这样做。

一旦你完成了所有这些,你可以克隆你的新裸回购(这实际上创建了一个正常的回购,也是你如何将它从裸转换为正常)

当然,如果你有其他的上行流,你会想要记录它们,并更新你的裸回购以包括它。但是同样,这一切都可以用git命令来完成。请记住手册页是您的朋友。

除非您特别想要或需要在文件系统上摆弄比特,否则创建一个非裸库的裸版本真的非常简单(在这里的其他几篇文章中提到过)。它是git核心功能的一部分:

Git clone——bare existing_repo_path bare_repo_path

如果你有一个存储库,只有很少的本地签出分支/refs/heads/*和很少的远程分支分支/origin/* and,如果你想把它转换成一个BARE存储库,所有分支都在/refs/heads/*中

您可以执行以下操作保存历史记录。

创建裸存储库 CD到具有本地签出分支和远程分支的本地存储库中 Git push /path/to/bare/repo +refs/remotes/origin/:refs/heads/

我认为下面的链接会有帮助

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推送更改