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

主要的区别似乎是:

在普通的Git存储库中,您在存储库中有一个.git文件夹,其中包含所有相关数据和构成工作副本的所有其他文件 在裸Git存储库中,没有工作副本,文件夹(让我们称之为repo.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号试图指出的答案。当然,人们可以重新发明轮子;-)

其他回答

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

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

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

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

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

(a)  mkdir backup

(b)  cd backup

(c)  git clone non_bare_repo

其次,运行以下命令:

git clone --bare -l non_bare_repo new_bare_repo

用于执行上述所有操作的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)