What Is Git and Git Flow? How To Use It?
February 5, 2023
Git is a distributed version control system, which is often used for version control, collaboration, and backup of software development projects. The related questions about Git often asked in interviews include: What is Git? What is Git Flow? And how to use it?
What is Git?
Git is a distribution version control system, which can record the changes of files. The process of Git version control is not to record the difference between versions, the process is as follows:
- Version 1: Add three files in the folder, namely
A
,B
. - Version 2: Add
C
,D
, thenA
,B
will point to theA
,B
of Version 1. - Version 3: Modify
B
,C
, thenA
will point to theA
of Version 1, andD
will point to theD
of Version 2.
Git data structure
Git has two data structures, namely object
and index
, the difference between them is as follows:
Object
The object is an immutable file type, stored in .git/object/
, and the object is hashed by the file content to get the file name. The object type can be divided into three types:
- blob object: Record the content of the file.
- tree object: Record which files are in a specific folder, and the corresponding blob object file name of the file, and can also contain tree objects, similar to the concept of folders.
- commit object: It will record the tree object, parent (the previous commit object), and other information.
There is another object that is not named by the hash value of the file:
- tag object: It will appear when adding a tag, and it will be stored in
.git/refs
, and it will always point to a specific commit object.
Index
It is located in .git/index
, which is a binary file, and it will be used to record which files need to be submitted to the repository. This index file usually saves the state of the specific version of the Git repository, which is between the working space and the repository.
What is Git Flow?
Git Flow is a Git extension, which is used to manage the development of Git projects. It is a branching model, which is used to manage the development of Git projects. The development process of Git Flow is as follows:
- master: It is in a production-ready state, which is runnable, fully functional, well-designed, and documented.
- develop: The latest state of the next release version, which is mainly branched out from the master branch, and the code that the automated test is based on will be branched out from this branch for testing.
- feature: It is branched out from the develop branch, which is mainly used to develop new features, and it will be merged back to the develop branch after development.
- release: When the develop branch is mature enough, it can be merged back to the release branch, which is the last test before going online. After the test is completed, it will be merged back to the develop branch and the master branch.
- hotfix: It is branched out from the master branch. When a product is online and an urgent problem occurs, a hotfix branch will be opened to fix it.