Hello, everyone. I’m Xiao Qi

preface

Git is one of the programmers write programs necessary tools, to do a good job, must first sharpen his device obviously the weapons come just for me to play the function of it is the most simple, it’s not, two days before I was on the branch or the wrong code, although colleagues said nothing, but this is should not be made the mistake, so I decided to Git for a more detailed study and summary.

Git is introduced

Git is an open source distributed version control system that can effectively and quickly manage the versioning of very small to very large projects. It does not require network support, and has become the first choice for many developers for project versioning, as well as for managing their own generic document versioning.

There are a lot of Git commands, which only need to be used in a few simple commands in daily development. Therefore, this article will start with the noun parsing and then introduce the application of Git _ common commands in projects.

Noun parsing

For Git can be downloaded from the official website to use, in the introduction of the command also to understand a few concepts

The workspace

It’s a directory that you can see on your computer, and it’s a directory that contains all the files you’re working on

repository

There is a hidden file in your workspace called.git. This is Git’s repository. The repository contains the staging repository called stage, the first branch that Git created for you, and the pointer to the master, HEDE

Remote warehouse

A code repository created on a GitHub, GitLab, or GitEE writing platform and associated with a local repository allows you to upload version projects or documents

Common commands

Git commands are commonly used at work

  • git config
  • git init
  • git clone
  • git status
  • git add
  • git commit
  • git log
  • git reset
  • git push
  • git pull
  • git stash
  • git branch
  • git checkout
  • git merge
  • git fetch
  • git tag

The use of such a command will be explained in the following sections

git config

Configure personal information, including user name and mailbox

git config --global user.name "my name"
git config --global user.email "my email.com"

In this way, the submission records submitted after the code will have their own personal information. Some companies will also review the code according to the information submitted by the code to determine the year-end evaluation bonus, etc

ssh-keygen -t rsa -C "my email.com"

Create the secret key, put the generated secret key in the ~/.ssh directory, press enter all according to the prompt, put the public key in the GitHub warehouse after the operation is completed, and then the operation project can be entered without secrecy

git init

Initialize the Git repository

git init

Initialize a Git repository

git clone

Clone remote repository

Git clone < link to >

The remote repository’s items are downloaded locally from the current folder

git status

View the status of file changes

git status

You can see if the files in the project are committed

git add

Submit workspace files to staging area

Git add < filename > git add

Is the first step in submitting the document

git commit

Commit the workspace files to the Git repository

Git commit -m < commit message >

The second step of submitting the file

Git commit -- amend-m < New commit message >

Amend The parameter –amend allows not only to modify the submission information, but also to replace the previous submission if there are changes to the register

Submission information specification

  • fix: Fixed one bug
  • feat: A new feature has been added
  • refactor: Refactor a piece of code
  • perf: Improved performance
  • docs: Document related
  • test: Test Related
  • ci:CI/CDrelated
  • chore: Other types

For example, if a new login feature is added, the submission information can be added for, FEAT: Login feature

git log

View the version commit record

Git log --pretty=oneline // Output commit information in oneline

You can view the submission information of the version, including the submission person, date, reason for submission, unique submission number, etc

git reset

Version back

git reset --hard HEAD^

Head ^ reverts back to the previous version and commits back to the previous version. Head represents the version, and HEAD~ n represents the previous n versions

git push

Push files from your Git repository to a remote repository

You can give the remote repository an alias before committing

Git remote add [alias] git remote add [alias]
Git push -u [alias]

The last step of submitting the file, -u is used for the first push and can associate the local branch with the remote repository branch. After that, you don’t need to add the -u argument to the submission.

git pull

Pull the latest code from the remote repository locally and merge it

Git pull [alias]

The ability to pull code from a remote repository and merge it locally is equivalent to Git Fetch and Git Merge

git fetch

It just pulls the remote repository code

Git fetch [alias]

Fetching an update returns a FETCH_HEAD, which is the latest state of that branch on the server, and can be viewed locally with git log-p FETCH_HEAD

This information is used to determine if there is a conflict and to determine whether to merge updates into the current branch

git merge

The specified branch is combined with the code to the current branch

Git merge < >

Conflicts may occur when merging code, resolve them and run normally

git stash

Save current changes

git stash

If you save the current modified version, you can switch to another branch or pull a remote branch without conflict

git stash pop 

Take out the saved version

git stash list

View all saved version information, the store can be directly indexed by the location of the stash@{n}.

git branch

The operation of adding, deleting, changing and checking branches

git branch

View the list of local branches

Git branch < >

Create a new branch and name it

Git branch -m < old branch name > < new branch name >

Modify the local branch name

Git branch -d < >

Delete local branch

Branch naming convention

  • master The main branch
  • developDevelopment branch
  • feature/xxxNew function branch
  • bugfix/xxxrepairbugbranch
  • hotfix/xxx Hot repair branch, repair emergencybug
  • release/x.x.xNew version branch

git checkout

Switch branch

Git checkout < branch name >

Switch to the specified branch

git tag

Mark milestones for the project

Git tag < tag name >

You can mark the project code at an important node

conclusion

The above command just git common commands, the master, to deal with the daily development is completely enough, with a view of the complex, Google it, remember to bring your problems and solutions are recorded oh, such similar problems can extrapolate again, every tread pit into your growth

I am small seven, a program like to read a little sister, there are a lot of new career need to learn, like to share their own life and vegetable chicken technology summary, interested in the search WX search, I said girl, pay attention to me, and I grow up together!