This is the copy of alvincr.com

NO Title!

Personal blog: alvincr.com, if updated: https://alvincr.com/2021/01/git-and-github/

One: background

I wrote an article about building GitHub_Pages two days ago, and I used Git. I can’t help but wonder what the relationship between GitHub and Git is, and why is Github named after it?

Two: Git

1 Basic knowledge

First, let’s first understand what Git is.

Git is a version control tool for Linux kernel development. Unlike centralized version control tools such as CVS and Subversion, it adopts a distributed version library approach, and version control can be operated without server-side software, making the release and exchange of source code extremely convenient.

2 Git features

Git is a distributed version control software, we can see in just this sentence:

  1. Git usage scenarios are distributed rather than centralized management, so the object of use should be a personal PC;
  2. The role of Git is to version control files.

In addition, Git has the following features:

  1. Git is developed in C language to pursue the highest performance.
  2. Git can automatically complete garbage collection, or it can be called directly with the command git gc -prune.
  3. The typical TCP listening port of the Git server is 9418.
  4. Git uses the packs operation to compress files into a file (packfile) using differential compression. Both packfile and index files use SHA-1 as the checksum and the file name.

3 The biggest advantage

The biggest advantage of Git is that it can record the contents of file modifications step by step and time, which has an incomparable advantage for saving historical files and multiple people modifying files together.

(1) Save historical files: Since Git only records the modified content, other unmodified content does not need to be saved additionally, saving a lot of storage space.

(2) Multi-person modification: Suppose alvincr wrote a program today. God A looked at the bugs in the program and took away a backup to modify the bugs. Alvincr looked at his program and found that the bugs were indeed piled up. Modified a bit. The next day, God A passed the modified program to me. At this time, I must think about what I modified myself, what was modified by God, and how to combine the two. The bitterness is hard to explain. Using Git can directly solve such pain points, using Git can directly record the modified content and then automatically merge it.

4 Comparison with other management methods

The management systems that have the same effect as Git include CVS, Subversion, and Perforce. Although they are similar in effect to Git, the principles of implementation are completely different.

The following content is summarized from the official Git website: https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-Git-%E6%98%AF%E4%BB%80 %E4%B9%88%EF%BC%9F , other reference: WIKI

  1. Git directly records snapshots and builds indexes

CVS, Subversion, Perforce, Bazaar and other management methods: It is a delta-based version control, that is to say, the differences between two files (1V1) will be found, and only the differences between the two will be recorded.

Git first builds an index based on all initial files (multiple Vs), if you add other content, then only build the index of the content you added.

Personal understanding: CVS is equivalent to the class teacher, each class teacher is responsible for recording the changes of each class, and only when there is a change in the class, the class teacher will report to the school; Git is equivalent to the head of the level, recording the overall changes of the entire level every period of time, Only record the changed part and report it to the school. That is: CVS is responsible for a single file, and Git is responsible for the entire file.

The following pictures are from the original text (please forgive the original author if the watermark is automatically added):

Use CVS, Subversion, Perforce, Bazaar

Store the difference between each file and the initial version.

Use Git

Git stores snapshots of project changes over time.

  1. Git stores almost all files locally

There is a complete history of the project on the local disk, but it depends on the network.

  1. Git can only add data

Since only data can be added, using Git will not cause accidental deletion of database data, so Git will basically not perform any operations that may cause files to be unrecoverable. But like other VCS, the modified content may be lost or messed up when the update is not submitted.

5 Supplement: CVS bottleneck

Original: https://developer.ibm.com/zh/devpractices/devops/articles/os-cn-git-and-github-1/

The storage and copying of the code base is not the bottleneck of the version control system. Analyzing the differences in files and viewing the historical versions of the code base are often the real bottleneck. Based on the design of this snapshot stream, Git can quickly obtain all the files in the code base at a certain moment, and it can also quickly compare the differences between the historical versions of the files, and even the entire code base of each historical version or branch. Difference comparison. Imagine if it is a traditional incremental storage method, a code base has been developed for a long time, assuming that the code base has 100,000 files, and each file has undergone an average of 100 modifications, then the latest code base and the original code must be retrieved The difference in the library requires 10 million increments to be retrieved before the final successful comparison, which requires an unimaginable time cost. Git does not have this problem. Git only needs to retrieve the latest code base snapshot and compare the original code base snapshot directly. Relying on Git’s diff algorithm (Myers algorithm), Git can retrieve the two efficiently and quickly. The difference comes.

Three: GitHub

1 Introduction

Official website introduction: https://github.com/about

GitHub is the world’s largest open source code hosting platform. (Finish)

2 function

Common options

Creating a new warehouse is equivalent to creating a new folder on the hard disk. This folder is used to store a certain project file.

img

Fork command can copy other people’s resources to this folder of your own.

Star is used for collection, equivalent to favorites

img

Clone can copy other people’s files or your own warehouse on github to local

img

In addition, if you are visiting a personal warehouse, you can also modify and add files online

img

Browse Github

You can choose explore github on the github homepage, through this option you can view the articles recommended by github

img

img

Four: the relationship between the two

(1) GitHub is a code hosting platform, and it utilizes Git-based hosting services.

(2) Git source code is also available on GitHub.

(3) Files on github can be cloned via git (login required).

img

Personal guess: GitHub takes this name because it mainly uses Git, and the main storage method of Github is also based on Git, so the data we upload on Github will have historical versions, which is very friendly to find.

Attach:

.git folder

Reference article: https://juejin.cn/post/6844903986839945229

The newly created Git folder has the following files by default:

img

Config file:

Set up some information about .git here.

img

Descripton:

img

This file is used for GitWeb. GitWeb is a CGI script (Common Gateway Interface, which is simply a program running on a web server, but triggered by browser input) that allows users to view git content on web pages. If we want to start GitWeb, we can use the following command:

# Make sure lighttpd is installed: brew install lighttpd

$ git instaweb –start

By default, the lighttpd service will be started and the browser http://127.0.0.1:1234 will be opened. The page directly displays the current git warehouse name and description.

Personal test the code given above is invalid:

img

Hooks file:

Hooks store the files submitted by git at various stages, which are used to check before and after the git command or do some custom actions.

img

HEAD:

Modifying the content in the head can change the position of the pointer to point to the desired work partition.

img

Objects:

Original: The default format used by Git to save objects to disk is the loose object format. When you modify even one line of the same file, git will use a new file to store the modified file and place it in objects. Git packs these objects into a binary file called packfile from time to time to save space and improve efficiency

In summary, objects are equivalent to the temp folder.

Ref:

Store the branches of git generated files and the use of tags.

  1. 1.
    1. 1.1. Personal blog: alvincr.com, if updated: https://alvincr.com/2021/01/git-and-github/
    2. 1.2. One: background
    3. 1.3. Two: Git
      1. 1.3.1. 1 Basic knowledge
      2. 1.3.2. 2 Git features
      3. 1.3.3. 3 The biggest advantage
      4. 1.3.4. 4 Comparison with other management methods
      5. 1.3.5. 5 Supplement: CVS bottleneck
    4. 1.4. Three: GitHub
      1. 1.4.1. 1 Introduction
      2. 1.4.2. 2 function
    5. 1.5. Four: the relationship between the two
    6. 1.6. Attach:
      1. 1.6.1. .git folder