This section describes Git’s common commands and basic operations in detail. You can use the following command to display the help documents of related commands.

git help <command>
Copy the code

24.4.1 Warehouse Management Commands

1. The git init

Initialize Git repository.

After the git init command is executed, a. Git directory is generated in the local directory, which contains all metadata of the resource.

2. Git clone

Function: replication repository, default will only create the master branch. The basic usage is as follows.

Git clone remotes/origin/dev git clone XXX dir_nameCopy the code

The following is an example.

git clone https://github.com/mingongge/doc.git docgit
Copy the code

3. The git add

Function: Submit file to temporary storage area. The basic usage is as follows.

Git add # Commit the specified file to the staging areaCopy the code

4. The git commit

Function: Submit a staging file to a remote repository. The basic usage is as follows.

Git commit-am"Copy the code

24.4.2 Branch Management Commands

1. The git branch

Function: Create branch. The basic usage is as follows.

Git branch -d branch_name # Delete the specified branchCopy the code

2. The git checkout

Function: Switch branches. The basic usage is as follows.

Git checkout branch_name # Switch to a branchCopy the code

3. The git pull

Function: Pulls updates from all branches of the remote repository and merges them locally. The basic usage is as follows.

Git pull master # Pull the update from the master branch of the remote repository locally and merge it with the local master branch

4. Git push

Function: Push all branches of a local repository to a remote repository. The basic usage is as follows.

Git push -u origin master git push -u origin master Git push origin <local_branch> Git push origin <local_branch>:<remote_branchCopy the code

24.4.3 Viewing Operation Commands

1. The git diff

Function: View the differences between compare files and versions. The basic usage is as follows.

Git diff <branch1> <commit2> git diff <branch1> <branch2> # compare staged differences git diff --cached # Compare staged differences git diff --stat # Compare statistics onlyCopy the code

2. The git log

Function: View submission records. The basic usage is as follows.

Git log -p git log -p git log -p git log -p git log -p View commit statisticsCopy the code

3. The git show

Function: Used to display various types of objects (one or more, e.g., labels, submissions). The basic usage is as follows.

Git show v1.0.0 --format=s% git show v1.0.0 --format=s% V1.0.0 ^{commit}# displays the submitted topic that the tag v1.0.0 points toCopy the code

4. The git status

Function: Used to display the status of working directories and staging areas. The git status command displays three file states, as follows:

(1) Files that have been added to the staging area but have not been committed.

(2) The file has been modified but not added to the staging area.

(3) Documents tracked. The basic usage is as follows.

Git status --short # Git status --short # git status --short #Copy the code

24.4.4 Other Commands

1. The git tag

Function: Used for labeling and marking. The basic usage is as follows.

Git tag -d v1.0.0 git tag -d v1.0.0 git tag -d v1.0.0 git tagCopy the code

2. The git remote

Run the following command to view information about an associated remote warehouse: The basic usage is as follows.

Git remote rename name1 name2 git remote rm name Git remote add name url git remote add name urlCopy the code

This article is excerpted from Linux System Operation and Maintenance Guide: From Entry to Enterprise Practice

 

This book is mainly based on a quick start and learning Linux system as the starting point, explaining basic theory first, then explaining practical operation, from simple to deep, combining basic theory with practical application of enterprises.

The biggest feature of this book is the real operation and maintenance environment for the enterprise. The book is divided into four, base paper introduces in detail the basic knowledge of Linux system, LAMP/LNMP architecture article introduces the current enterprise in two of the most common architecture deployment and configuration of application service report to enterprise actual operational environment as the starting point in detail the present enterprise use of all kinds of open source software services, architecture used for the first three papers to summarize knowledge, And combined with the actual scene of the enterprise to practice. In this way, readers can have a complete and clear understanding of the operation and maintenance work of the actual scene of the enterprise. While getting a quick start, they can also learn the necessary skills in the actual working environment of the enterprise.