Guide catalog

  • 1. Why use Git version control

  • 2.Git file structure and storage principle

  • 3.GitFlow branch development specification

  • 4.Git FAQs and Solutions

  • Continuous integration and Agile development

1. Why use Git version control

Defects of the SVN

The advantages of Git

1.Git stores the content in the form of metadata and hash. Every submission is a mirror image of the whole project.

2. Each client source can be used as a Clone object. Contains all elements of the central version library.

The difference between

All systems are files, SVN on the left, Git on the right. Git takes a complete snapshot of the project every time it commits.

2.Git file structure and storage principle

Git file structure

When you execute git init in a new or existing directory, git creates a.git directory. This directory contains almost all the objects that Git stores and manipulates.

All systems are made up of files. These files manage versions of a project.

Git storage

File storage, the more versions, store more information, and run slower.

Below is a snapshot of a tree generated by a COMMIT.

As long as the contents of the file are the same, it is a BLOB (regardless of its path),

A Git commit, the commit information is refreshed, this time producing the hash value of the changed file, known as blob,

Git uses the hash value for the file name to compare differences. Whenever a file changes, the hash value of the file will change, and the file name will be different from the old version. This information will be passed up the folder, resulting in the creation of different trees containing these different bloBs.

Emm… Think down the line…

A file whose contents change after modification produces two BLOBs. The more times the file is modified, the more bloBs it produces. Increasing memory footprint?

Git gc .

Git’s default format for saving objects to disk is called the loose Object format. Git from time to time packages these objects into a binary called packfile to save space and improve efficiency. Git does this when there are too many loose objects in the repository, git GC commands are called manually, or pushed to a remote server.

Why does Git create branches so quickly?

Open your project’s Git directory, find a branch, open it, and look for the SHA-1 string inside.

We can switch between branches at will, all in a flash.

Git basic Name

Git basic operation commands, here do not do too much verbose, this section will focus on the two confusion in Git.

Reset is different from Revert

Git reset rolls back the code to a commit point and deletes the previous version.

Git Revert If you want to restore a previous version without deleting the previous version (this version is not merge, but you want to keep the later version of the target version and keep track of the entire version change process).

Work area and staging area

The add command now temporarily has two functions: 1. Add files to the tracked state 2. Commit files from workspace to staging and Commit to repository.

  1. Repository level configuration files:.git/.gitconfig in the repository, which are only valid for the repository.
  2. Global configuration files: ~/.gitconfig for Mac systems, C:\Users< username >.gitconfig for Windows systems.
  3. System-level configuration file: gitconfig in the etc folder of the Git installation directory (/usr/local/git on Mac).

Now that you know why git is used, it’s time to prepare SVN to migrate Git

Now that you know why git is used, learn about git branch management and gitflow


3.GitFlow branch development specification

Trunk branch Master (the latest release for the project),

The master branch is usually combined with the Develop and Hotfix branches and cannot be modified at any time

Develop (for the latest code)

When developing new features, the feature branch is created under The Develop branch

Business Branch Module

Freight, scheduling, and so on. Business line Module/Freight

Feature branch feature

Develop a feature branch that starts with a feature branch based on Develop. For example, experimental code changes that don’t work well can be initiated from Develop and the feature branch must be merged back into develop

Branch naming: Feature/naming rule: Feature/sharing function, module/ freight _feature/login function, feature/ SONAR scanning error modification

The release branch

Release branch A branch created specifically for releasing a version. It can also be called a pre-production environment. You can also use the master branch +tag method instead.

Typically created from the develope branch. When the code on the Develop branch contains all the functionality planned for the release version and has passed all the tests, we can consider preparing to create the Release branch.

That is, after development and testing, we are ready to release the branch release/v1.0.0,

Once created, only minor bug fixes are allowed, along with all the information required to prepare the release (version number, release date, channel distribution, and so on). Checkout the release/ XXX branch from the master tag and checkout the release/ XXX branch.

After successful release, be sure to updateThe release/v1.0.0Develope.

Other branches

Issue branch: used for project code review, or rectification of issues proposed by GitLab. Name it issue/ Code security Hardening

Hotfix branch: This branch is used to fix bugs online. It is created on a specific release branch and pushed to the corresponding Release branch at the same time. After testing, it is pushed to the Develop branch and master branch.

Development iterative thinking

Common iterative thinking

–> New project -> Create develope branch, Master branch -> Requirements -> Develop on develope branch -> Merge Other code -> Finish features -> Test Test on develope branch -> Test end -> Switch to Master branch,merge Develope code -> Package, tag v1.0.0—–> Next requirement.

Agile iterative thinking

4.Git FAQs and Solutions

1. How to modify git commit MSG?

You are not advised to modify a commit messge!!!!!! Commit changes to commitiD, which means that this is a new commit and will disrupt the order of the commit tree.

2. Why cannot the account name and email address name be changed?

1. Local: in. Git /config, git configuration defaults to local for the current repository configuration

Git config [--local] user.name Specifies the user name of the git repository. Git config [--local] user.email Specifies the user email address of the git repositoryCopy the code

2. Global, in the personal home directory, for the current system user’s repository

Git config --global user.email Git config --global user.email git config --global userCopy the code

3. System, under the Git installation directory, is the repository for all users of the current operating system. (This level is not normally used to configure user information)

Git config --system user.name Git config --system user.email Git config --system userCopy the code

3. How do I ignore files that do not need to be submitted?

Use the.ignore file

.ignore in the same directory as.git. You can customize rules

PS: What if I added git management to it, but now I want to ignore it?

After editing your.ignore file, execute the following command

git rm -r --cached . 
git add .
git commit -am "Remove ignored files"Git pushes your remote repositoryCopy the code

4. Oops, what if the code is accidentally pushed to a remote repository?

Git revert your commitID.

5. When a colleague submits code, my branch only wants some of his codecommit?

Cherry -pick.

  • Switch to the branch that selects colleagues
  • Choose a few that you wantcommit
  • forcherry-pickoperation

6. If the submission record was accidentally lost, is there any remedy for regret?

Git reflog: Git reflog: Git reflog

7.Idea Git plugin, others branch to submit code,

Do you want to merge your branch?

Git is distributed and refresh is useless!! … You need to re-pull the remote code to update the local repository. The latest submission records are available.

8. Why can’t I merge or cherry-pick commit records?

Git commit sort by time!!!!!! The newer the Commit time is, the earlier it is and whether the log is the current branch.

####9. Other precautions

  • git push -fIt will empty the previous commit record.
  • Public branchmasteranddevelop, cannot proceedrebaseOperations, in principle, can only change their own branches.
  • Before the push code, try to pull the code and update the remote code to the local. After the merge is complete and the operation is normal, perform the push operation.
  • To avoid code conflicts, the local repository is pushed to the remote GitLab in time

6. Sustainable integration

Continuous Integration (CI), also known as Continuous integration(CI), is a software development practice in which team development members frequently integrate their work, meaning that integration may occur multiple times per day by having each member integrate at least once per day. Each integration is verified by an automated build (including compilation, release, and automated testing) to catch integration errors early.

There are two ways

  • gitlab+Jenkins

  • gitlab+gitlabCI

Production model

Jenkins

Jenkins is a scalable continuous integration engine.

The main function

  • Build/test software projects continuously and automatically.
  • Monitor some scheduled tasks.

Major configurable items

  • Customize build parameters
  • Execute gradle, Maven and other project scripts
  • Timing task
  • Mount GitLab, Sonar and other third-party platforms
  • The interface is highly customizable

Jenkins Business Process

  • Project configuration
  • Customize build parameters
  • Custom build log output
  • View build logs, error logs
  • Object file generation
  • Build completion notification (pins, test emails, etc.)

Jenkins pipeline Mission

6. Other

Commonly used tools

With Mac, Linux, or Windows, there will be a corresponding Git graphical management interface, mainly to display IDEA plug-ins.

  • sourcetree
  • Git plugin for IDEA
  • The Git command
  • TortoiseGit

The idea, for example

How to use Git for team CodeReview?

  • GitLab Setup protection branch (current mode)
  • Git + Gerrit

About Me

github: https//github.com/ccj659/

Jane: http://www.jianshu.com/u/94423b4ef5cf

CSDN:http://blog.csdn.net/ccj659/article/