Git local library operations
Local library initialization
That is, to create out of the local library
Command: git init
Create a folder, open the folder context menu Git Bash Here
window, enter the command
You can see the display initialize an empty git repository folder in the file we created, we can check to see hidden files you can see the generated folder.
!> Note: The .git
directory is stored in a local library related directories and files, do not delete and do not tinker.
Signature settings
This string can be used to distinguish the identity of the developer.
form:
用户名:chenjiaxing
邮箱:[email protected]
!> Set here login signatures and remote database (that is, code hosting centers) account password does not have any relationship.
command:
git config --global user.name chenjiaxing
git config --global user.email [email protected]
Project-level / warehouse level: only valid within the current range of local library
- git config
System user levels: User login scope of the current operating system
- git config --global
Level priority: project-level priority system to the user level, both have the time, the use of project-level signature. If only the system user-level signature, it is subject to the system user level.
Both are not allowed to!
General user level we would not have to create each project to set it up, general project-level configuration information .git folder, and user level in the current .gitconfig file in the user directory system, you can use cd ~
the name switch to the current user folder, and then view it.
Git basic commands
1) Status View
git status
查看工作区、暂存区状态
When you enter a command in the initialization of new projects:
2) Add
git add [file name]
将工作区的“新建/修改” 添加到暂存区
3) submit
git commit -m "commit message" [file name]
将暂存区的内容提交到本地库
4) View History
Multi-screen display control mode:
- Space Down
- b Page Up
- q quit
git log
:
git log --pretty=oneline
:
git log --oneline
:
git reflog
:
::: tip Tip:
the HEAD @ {move to the current version of how many steps required}
:::
5) forward and back
!> Nature: Move the pointer
Based on the index value of the operation [Recommended]
git reset --hard [局部索引值] 如:git reset --hard a6ace91
Use the caret: only retreat
git reset --hard HEAD^ 注:一个^表示后退一步, n 个表示后退 n 步
Use the tilde symbol: only retreat
git reset --hard HEAD~n 注: 表示后退 n 步
three parameters compared reset command:
- --soft parameters: HEAD only move the pointer local library
- --mixed: parameter local library HEAD pointer movement, the reset staging area
- --hard parameters: HEAD pointer moves in the local library, the reset staging area, the work area resetting
6) to retrieve deleted files
Prerequisite: Before deleting, the file exists when the state submitted to the local library.
operating:
git reset --hard [指针位置]
Delete operation has been submitted to the local library: pointer to point to the location history
git reset --hard a6ace91
Delete operation has not been submitted to the local library: the pointer position using HEAD
git reset --hard HEAD
7) Comparison of file differences
operating:
The workspace file and compares the staging area
git diff [文件名]
The files and local history library workspace compare
without a file name to compare multiple files
git diff [本地库中历史版本] [文件名]