我一直在阅读Git中的裸库和非裸库/默认库。我还不能很好地(从理论上)理解它们之间的区别,以及为什么我应该“推送”到一个裸库。事情是这样的:
目前,我是唯一一个在3台不同计算机上从事项目的人,但以后会有更多人参与其中,所以我使用Git进行版本控制。我在所有计算机上克隆裸回购,当我完成对其中一台计算机的修改时,我提交并将更改推到裸回购。据我所知,裸库没有“工作树”,所以如果我克隆裸库,我就不会有“工作树”。
我猜工作树存储了来自项目的提交信息、分支等。这不会出现在裸回购中。因此,对我来说,用工作树将提交“推”到repo似乎更好。
那么,为什么我应该使用裸库,为什么不呢?实际的区别是什么?我想,这对更多人参与一个项目没有好处。
你做这种工作的方法是什么?建议吗?
我当然不是Git“专家”。我使用TortoiseGit有一段时间了,当我创建一个“裸”回购时,它问我是否想要创建一个“裸”回购,我想知道它在说什么。我正在阅读这个教程:https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init,它解决了这个问题,但我仍然不太理解这个概念。这个帮助很大:http://bitflop.com/tutorials/git-bare-vs-non-bare-repositories.html。第一个也说得通!
According to these sources, in a nutshell, a "bare" repo is used on a server where you want to set up a distribution point. It's not intended for use on your local machine. You generally push commits from your local machine to a bare repo on a remote server, and you and/or others pull from that bare repo to your local machine. So your GitHub, Assembla, etc. remote storage/distribution repo is an example where a "bare" repo is created. You would make one yourself if you were setting up your own analogous "sharing center".
裸库和非裸库的另一个区别是,裸库没有默认的远程源存储库:
~/Projects$ git clone --bare test bare
Initialized empty Git repository in /home/derek/Projects/bare/
~/Projects$ cd bare
~/Projects/bare$ git branch -a
* master
~/Projects/bare$ cd ..
~/Projects$ git clone test non-bare
Initialized empty Git repository in /home/derek/Projects/non-bare/.git/
~/Projects$ cd non-bare
~/Projects/non-bare$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
从手册页的git克隆——bare:
同时,分支的头在远程
是否直接复制到相应的
本地分支头,没有映射
它们指向refs/remotes/origin/。当
这两个选项都没有使用
远程跟踪分支机构也没有
相关配置变量为
创建。
假设,在创建裸存储库时,Git假定裸存储库将作为几个远程用户的原始存储库,因此它不会创建默认的远程源存储库。这意味着基本的git pull和git push操作将无法工作,因为git假设没有工作区,你不打算向裸库提交任何更改:
~/Projects/bare$ git push
fatal: No destination configured to push to.
~/Projects/bare$ git pull
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
~/Projects/bare$
The distinction between a bare and non-bare Git repository is artificial and misleading since a workspace is not part of the repository and a repository doesn't require a workspace. Strictly speaking, a Git repository includes those objects that describe the state of the repository. These objects may exist in any directory, but typically exist in the .git directory in the top-level directory of the workspace. The workspace is a directory tree that represents a particular commit in the repository, but it may exist in any directory or not at all. Environment variable $GIT_DIR links a workspace to the repository from which it originates.
Git命令Git clone和Git init都有选项——bare,可以在没有初始工作区的情况下创建存储库。不幸的是,Git将工作空间和存储库这两个独立但相关的概念合并在一起,然后使用令人困惑的术语bare来区分这两个概念。