我如何将一个“正常”的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

其他回答

首先,备份你现有的回购:

(a)  mkdir backup

(b)  cd backup

(c)  git clone non_bare_repo

其次,运行以下命令:

git clone --bare -l non_bare_repo new_bare_repo

简而言之:用repo/的内容替换repo的内容。Git,然后告诉存储库它现在是一个裸存储库。

为此,执行以下命令:

cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true

注意,这不同于做一个git克隆——裸到一个新的位置(见下文)。

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

Git clone——bare existing_repo_path bare_repo_path

简单的读

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号试图指出的答案。当然,人们可以重新发明轮子;-)

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

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

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