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

主要的区别似乎是:

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


当前回答

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

GitFaq:如何使现有的非裸库变得裸?

$ mv repo/.git repo.git
$ git --git-dir=repo.git config core.bare true
$ rm -rf repo

其他回答

我只是想推到网络路径上的存储库,但git不会让我这样做,除非该存储库被标记为裸。 我只需要改变它的配置:

git config --bool core.bare true

除非你想保持文件整洁,否则没必要乱动。

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

Git clone——bare existing_repo_path bare_repo_path

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

GitFaq:如何使现有的非裸库变得裸?

$ mv repo/.git repo.git
$ git --git-dir=repo.git config core.bare true
$ rm -rf repo

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

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

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

以下是我认为最安全、最简单的方法。这里没有没有上面说过的。我只是想看到一个答案,显示一个安全的一步一步的程序。您从想要使其为空的存储库(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