git init and git init -bare differences and solve problems without source files can not look at www

git init and git init -bare difference
engaged in web development people, sometimes encounter such problems in the development of the site, create a warehouse in the web or www directory server, each development will push up, direct deployment, and can be accessed directly, but in the creation of the warehouse, fix it appears no HTML web directory, js, php file is related to the git init command


Use the command "git init --bare" git --bare init a meaning, (bare Chinese meaning is: naked, nude)

Initialization of the repository (for the time being called a bare repository) will generate a class file : It is in the local directory can see the file under the .git directory for .git directory records repository history file;
and It does not contain a copy of the actual project source files ; so the repository can not be called the working directory (working tree);
if you enter the version of the directory, you will find only files in .git directory, and no other files;
when we visit the site when you can not visit, because there is no HTML files Well.
That is, the inside of the repository .git directory files are files in .git directory inside the original file in the root directory of the repository below;

[root@slh githome]# git init --bare
Initialized empty Git repository in /home/echo/githome/
[root@slh githome]# ll
total 32
drwxr-xr-x. 2 root root 4096 2010-01-05 13:46 branches
-rw-r--r--. 1 root root   66 2010-01-05 13:46 config
-rw-r--r--. 1 root root   58 2010-01-05 13:46 description
-rw-r--r--. 1 root root   23 2010-01-05 13:46 HEAD
drwxr-xr-x. 2 root root 4096 2010-01-05 13:46 hooks
drwxr-xr-x. 2 root root 4096 2010-01-05 13:46 info
drwxr-xr-x. 4 root root 4096 2010-01-05 13:46 objects
drwxr-xr-x. 4 root root 4096 2010-01-05 13:46 refs

These files are meant

|-- HEAD         # 这个git项目当前处在哪个分支里
|-- config       # 项目的配置信息,git config命令会改动它
|-- description  # 项目的描述信息
|-- hooks/       # 系统默认钩子脚本目录
|-- index        # 索引文件
|-- logs/        # 各个refs的历史信息
|-- objects/     # Git本地仓库的所有对象 (commits, trees, blobs, tags)
`-- refs/        # 标识你项目里的每个分支指向了哪个提交(commit)。

In other words , when not in use -bare option, it will generate .git directories and files under version history, the history file on these versions stored in the .git directory; and the use of -bare option is no longer generated. git directory, but only generates .git directory version history file, these version history file is no longer stored in the following .git directory, but placed directly under the root directory of the repository


Write a good feeling about ah, just one meaning:
git repository history --bare only the init file, bare (bare) warehouse stores only history and meta information, does not maintain a working directory.

git init has a project source files, as well as the historical repository files, history files in the repository .git directory


With "git init" to initialize the repository, users can also at the server side perform all aspects of the case git directory. However, other users will be updated when push came prone to conflict.

Example, users in the directory (called a distal warehouse server) performs the operation git, and has two branches (master and B1), the current in the master branch. Updating the master branch of another user want to own in a local warehouse (called the local repository) to submit to the master branch on the remote repository, he knocked granted

git push origin master:master

Ever since the emergence of

Because the operation of the user on the remote repository is the master branch, and you want to submit updates to the master branch, of course, wrong.

But if it is submitted to the distal end of the warehouse on the free branch or can, for example,

git push origin master: b1 still be successful

The solution is to create a so-called bare warehouse use "git init -bare" method, was called naked because this warehouse is a warehouse only saved version of the information submitted by the git history,
but do not allow user to perform various git operations in the above, if you insist the operation, it will only get the following error ( "this operation must be run in
a work tree") this is the best reason is initialized to the distal end of the warehouse bare warehouse.

When you're developing a web site, using git init it
but there is a problem:
When a local warehouse push to a remote repository, if the remote repository is push a branch (if not then push the branch, there is no problem), then push results will not react before the file or content on the work tree, that is in the directory corresponding to the remote repository.
Solution : the server must run the command: git reset -hard to see the contents of the push.
So good trouble

You may experience this problem
Git: push to resolve the error master -> master (branch is currently checked out)
due to the git push refused default, you need to set, modify server-side .git / config add the following code:


[receive]
denyCurrentBranch = ignore


Published 175 original articles · won praise 76 · Views 230,000 +

Guess you like

Origin blog.csdn.net/qq_29232943/article/details/60971061