1 Local library initialization
- Command: git init
- effect:
- Note: The subdirectories and files related to the local library are stored in the .git directory. Do not delete or modify them.
1.1 Set signature
- form
- Username: tom
- Email address: [email protected]
- Role: distinguish the identities of different developers
- Discrimination: The signature set here has nothing to do with the account and password for logging in to the remote library (code hosting center)
- command:
-
Project level/warehouse level: only valid within the scope of the current local library
- git config user.name tom_pro
- git config user.email [email protected]
- Information storage location: ./.git/config file
-
System user level: the range of users who log in to the current operating system
- git config --global user.name tom_glb
- confug sit --global user.email [email protected]
- The location where the information is saved: ~/.gitconfig file
-
Level priority:
- Proximity principle, project level takes precedence over system user level, both of which sometimes adopt project level signature
- If there is only a system user-level signature, the system user-level signature shall prevail.
- Neither is allowed.
-
2 Basic operation
2.1 Status check
git status
View the status of the workspace and temporary storage area
2.2 Add
git add [file name]
adds the "new/modified" of the workspace to the staging area
- Before adding:
- After adding
2.3 Delete
git rm --cached [file name]
delete the contents of the temporary storage area
2.4 Submit
git commit [file name]
Submit the contents of the temporary storage area to the local library
After modifying the file, execute git status and
execute the git add command to add the file to the temporary storage area.
Use the git commit -m "commit message" [file name] command , No need to enter the vim editor to edit this submission information
2.5 View history
git log
- Multi-screen display control mode:
- Space page down
- b Page up
- q Exit
git log --pretty=oneline
git log --oneline
git reflog
HEAD@{How many steps does it take to move to the current version}
2.6 Forward and Backward
Nature
-
Operation based on index value [recommended]
- git reset --hard [local index value]
- git reset --hard a6ace91
-
Use the ^ symbol: only go back
- git reset --hard HEAD^
- Note: A ^ means going back one step, n means going back n steps
-
Use ~ symbol: only go back
- git reset --hard HEAD~n
- Note: means back n steps
2.6.1 Comparison of the three parameters of the reset command
-
--Soft parameter
- Only move the HEAD pointer in the local library. The
local library moves backward, and the contents of the temporary storage area and work area are changed.
- Only move the HEAD pointer in the local library. The
-
--Mixed parameter
- Move the HEAD pointer in the local library
- Reset the temporary
storage area. Both the local library and the temporary storage area are backward. It appears that the workspace is updated but not added to the temporary storage area.
-
--Hard parameter
- Move the HEAD pointer in the local library
- Reset staging area
- Reset workspace
2.7 Delete files and retrieve them
- Prerequisite: Before deleting, the state of the file when it exists is submitted to the local library.
- Operation: git reset --hard [pointer position]
- The delete operation has been submitted to the local library: the pointer position points to the historical record
- The delete operation has not been submitted to the local library: the pointer position uses HEAD
2.8 Compare file differences
-
git diff [file name]
- Compare the files in the work area with the staging area
- Compare the files in the work area with the staging area
-
git diff [historical version in local library] [file name]
- Compare the files in the workspace with the local library history
- Compare the files in the workspace with the local library history
-
Compare multiple files without file name
3 Branch management
3.1 What is a branch?
In the version control process, multiple lines are used to advance multiple tasks at the same time.
3.2 Benefits of branching
- Simultaneously promote the development of multiple functions in parallel to improve development efficiency
- In the development process of each branch, if a branch fails to develop, it will not have any impact on other branches. Delete the failed branch and start again.
3.3 Branch operation
-
Create branch
- git branch [branch name]
-
View branch
- git branch -v
-
Switch branch
- git checkout [branch name]
- git checkout [branch name]
-
Merge branch
- The first step: switch to the branch that accepts the modification (to be merged, add new content) on
git checkout [name of the merged branch] - Step 2: Execute the merge command
git merge [Branch name with new content]
- The first step: switch to the branch that accepts the modification (to be merged, add new content) on
-
Conflict resolution
- Manifestations of conflict
- Conflict resolution
- Step 1: Edit the file and delete special symbols
- Step 2: Modify the file to a satisfactory level, save and exit
- The third step: git add [file name]
- The fourth step: git commit -m "log information"
Note: At this time, the commit must not carry a specific file name
- Manifestations of conflict