git is a distributed version control system that, compared to a centralized version control system like SVN, centralized version control systems can work collaboratively with multiple team members, but sometimes if a central server goes down, no one can commit updates and co-development during downtime. Even sometimes, a central server disk fails, and it happens that no backup or backup is in time, and there may be a risk of data loss.
But Git is a distributed version control system, and the client is not just extracting the latest version of the snapshot, but also copying the entire code warehouse image. If any server that works together fails, you can use any one of the code warehouses to recover. And while the collaboration server is down, you can also submit the code to the local repository, and when the collaboration server is working, you synchronize the local warehouse to the remote repository.
Install git
The Linux system uses the git command to view the installation, and if it is not installed, it can be completed by sudo apt-get install git.
After the installation is complete, further setup is required
git config--global user.name "name"
git config--global user.email "email address"
To create a version library
What is a repository? Repository also known as the Warehouse, English name repository, you can easily understand a directory, all the files in this directory can be managed by git, each file modification, deletion, git can track, so that any time can track history, Or you can "restore" at some point in the future.
Create an empty directory and use Git init under the current directory to turn this directory into a repository that git can manage;
After you have written a file, you can use git add filename to add the file to the repository;
Use git commit-m "your describe" to submit the file to warehouse-m parameters to describe the file changes, so that each view;
version View
Git status to view the status of a warehouse in real time
git diff filename to see the different files that were submitted on the current file
git log to view version history
Git reflog View history commands
Since HEAD in git is pointing to the current version, you can use git reset--hard commit_id (ID number of the submitted version or head^-previous version, head^^-version, head~100 on 100 versions)
version Fallback
1. You can use git checkout when you want to discard changes to the workspace--filename
2. When you have modified and submitted to staging area, you can use git reset HEAD filename to return to 1, and then repeat the 1 operation.
Deleting Files
git rm filename can delete files from the repository and commit with Git commit
Remote Warehouse
For configuration and cloning please refer to the Teacher Liao Blog Click to open the link
Branch Management
With git checkout-b branchname You can create a branch and switch to that branch, which is equivalent to command git branch branchname plus git checkout branchname (for switching between branches)
Git branch can view the branch, there will be a * before the current point
Merge a branch into the current branch git merge branchname (fast merge) can use git merge--no-ff-m "your Describ" branch to turn off quick Merge, this time you can see the merge
Delete branch git branch-d branchname
(when git cannot automatically merge branches, it means that there is a conflict to resolve the conflict before merging)
git log--graph can see the branch merge diagram
Git stash can stage the current work site and fix the bug, then git stash pop back to the job site
If you want to discard a branch that has not been merged, you can forcibly delete it by using git branch-d filename.
Multi-person cooperation
Git remote-v displays detailed remote library information
Git push origin branchname pushes local branch to, if failed, crawl remote new commit with Git pull
git checkout-b branchname origin/branchname local branch for creating and remote branch
Git branch--set-upstream branchname origin/branchname
Git pull fetches branches from remote
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Git version control