“git init”与“git init”有什么不同?和“git init --bare”?

“git init”与“git init”有什么不同?和“git init --bare”?

问题描述:

git init git init --bare 之间有什么不同?我发现很多博客文章需要 - bare 为他们的Git服务器?

What is the different between git init and git init --bare? I found that a lot of blog post requires --bare for their Git server?

From 手册页,它表示:

From the man page, it said:


--bare

创建一个裸仓库。如果未设置GIT_DIR环境,则将其设置为当前工作目录。

Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory

但它实际上意味着什么?是否需要为Git服务器设置 - bare

But what does it actually mean? Is it required to have --bare for the Git server setup?

Non-Bare Git Repo

这个变体创建一个带有工作目录的仓库,以便您可以真正工作( git clone )。创建它之后,您会看到该目录包含一个.git文件夹,其中包含历史记录和所有git管道。您在.git文件夹所在的级别工作。

Non-Bare Git Repo

This variant creates a repository with a working directory so you can actually work (git clone). After creating it you will see that the directory contains a .git folder where the history and all the git plumbing goes. You work at the level where the .git folder is.

另一个变体创建没有工作目录的仓库( git clone --bare )。你没有得到你可以工作的目录。目录中的所有内容现在都包含在上面的案例中。

The other variant creates a repository without a working directory (git clone --bare). You don't get a directory where you can work. Everything in the directory is now what was contained in the above case.

不使用工作目录的情况下需要git repos,因为您可以将分支推送到它并且不管理正在处理的内容。您仍然可以推送到一个不是空白的存储库,但是您会被拒绝,因为您可能会移动某个人在该工作目录中工作的分支。

The need for git repos without a working directory is the fact that you can push branches to it and it doesn't manage what someone is working on. You still can push to a repository that's not bare, but you will get rejected as you can potentially move a branch that someone is working on in that working directory.

因此,在一个没有工作文件夹的项目,你只能看到git存储它们的对象。它们被压缩并序列化并存储在其内容的SHA1(哈希)下。为了在裸仓库中获取对象,需要 git show ,然后指定要查看的对象的sha1。您不会看到类似于您的项目的结构。

So in a project with no working folder, you can only see the objects as git stores them. They are compressed and serialized and stored under the SHA1 (a hash) of their contents. In order to get an object in a bare repository, you need to git show and then specify the sha1 of the object you want to see. You won't see a structure like what your project looks like.

裸仓库通常是每个人都将工作移至其中的*仓库。没有必要操纵实际工作。这是一种同步多人之间努力的方式。你不能直接看到你的项目文件。

Bare repositories are usually central repositories where everyone moves their work to. There is no need to manipulate the actual work. It's a way to synchronize efforts between multiple people. You will not be able to directly see your project files.

如果你是唯一一个在项目中工作或者你不需要裸仓库不想/需要一个逻辑*的存储库。在这种情况下,其他存储库可能更喜欢 git pull 。这可以避免git在推送到非裸存储库时的反对意见。

You may not have the need for any bare repositories if you are the only one working on the project or you don't want/need a "logically central" repository. One would prefer git pull from the other repositories in that case. This avoids the objections that git has when pushing to non-bare repositories.

希望这可以帮助