Git notes
Git concepts
Git is a free, open source distributed version control system that can handle projects from small to large quickly and efficiently.Copy the code
Differences between Git and SVN
SVN is a centralized version control tool. It has a single centrally managed server that stores the revised versions of all files. The disadvantages are also obvious. Git is a distributed document control tool. Instead of taking a snapshot of the latest version of the file, the client can take a complete mirror image of the code repository. The failure of any of the co-working files can then be recovered using the local repository of other clients.Copy the code
Git Git
Name of the command | role |
---|---|
Git config –global user.name Git config –global user.name | Setting a User Signature |
Git config –global user.email | Setting a User Signature |
git init | Initialize the local library |
git status | View local library status |
Git add file name | Add to staging area |
Git rm –cached file path name | Removed from temporary storage |
Git commit -m “Log info” file name | Commit to a local library |
git reflog | View logs of the compact edition |
git log | View the full version of the log |
Git reset — Hard version number | Version of the shuttle |
git remote -v | View remote library aliases |
Git remote add Alias Specifies the address of the remote library | Create the alias |
Git push alias branch | push |
Git pull alias branch | pull |
Git Clone remote library address | cloning |
Git branch operations
What is a branch
In version control, multiple tasks are pushed at the same time, and for each task, we can create separate branches for each task. Using branches means that the programmer can separate his work from the main line of development, and develop his own branch without affecting the main line. For starters, a branch is simply a copy, and a branch is a single copy. (The underlying branch is actually a reference to a pointer.)Copy the code
Benefits of branching
1. Promote the development of multiple functions simultaneously and in parallel to improve the development efficiency. 2. Branches During development, the failure of one branch has no impact on other branches. Delete the failed branch and start again.Copy the code
Branch operation
Name of the command | role |
---|---|
Git branch Specifies the branch name | Create a branch |
git branch -v | See the branch |
Git Checkout branch name | Switch branch |
Git merge branch name | Merges the specified branch to the current branch |
conflict
The reason for the conflict: When merging branches, the two branches have two completely different sets of changes in the same place in the same file. Git can't decide for us which one to use. New code content must be artificially determined. Check status (two changes detected in a file)Copy the code
Resolve the conflict
1. Edit conflicting files, delete special symbols, and decide what to use 2. Add git commit to staging area 3.Copy the code
Basic use of Git
Take GitHup as an example
Git remote add: git remote add: git push: git pull: git pull: git clone: git cloneCopy the code