“git init"和“git init"有什么区别?和“git init --bare"? [英] What is the difference between "git init" and "git init --bare"?

查看:23
本文介绍了“git init"和“git init"有什么区别?和“git init --bare"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

手册页,它说:

<块引用>

--裸

创建一个裸仓库.如果没有设置GIT_DIR环境,则设置为当前工作目录

但这实际上是什么意思?Git 服务器设置是否需要 --bare ?

解决方案

Non-Bare Git Repo

此变体创建一个带有工作目录的存储库,以便您可以实际工作(git clone).创建它后,您将看到该目录包含一个 .git 文件夹,历史记录和所有 git 管道都在其中.您在 .git 文件夹所在的级别工作.

裸 Git 存储库

另一个变体创建了一个没有工作目录的存储库 (git clone --bare).您没有获得可以工作的目录.在上述情况下,目录中的所有内容现在都包含在 .git 文件夹中.

为什么要使用一个与另一个

需要没有工作目录的 git repos 是因为您可以将分支推送到它,并且它不管理某人正在处理的内容.您仍然可以推送到非裸的存储库,但您会被拒绝,因为您可能会移动某个人正在该工作目录中工作的分支.

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

裸仓库通常是每个人都将工作转移到的中央仓库.无需操纵实际工作.这是在多人之间同步努力的一种方式.您将无法直接看到您的项目文件.

如果您是唯一从事该项目的人,或者您不想要/不需要逻辑中心"的存储库,则您可能不需要任何裸存储库.存储库.在这种情况下,人们更喜欢 git pull from 其他存储库.这避免了 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 the man page, it said:

--bare

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

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

解决方案

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.

Bare Git Repo

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 .git folder in the above case.

Why You Would Use One vs. the Other

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.

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.

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.

Hope this helps

这篇关于“git init"和“git init"有什么区别?和“git init --bare"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆