5.1 Open a command line window
- After installing Git, in the margin Explorer, right-click to open the window, click on the Git Bash Here, Git command line window open, you can use the Linux command operations directly in the window:
5.2 Initialization local Git repository
Command: git init
effect:
Note: .git directory is stored in a local library related core configuration files, and do not arbitrarily delete and modify
- .git directory in the repository directory Explanation:
- hooks directory: directory script file.
- info directory: management does not want to save the file in .gitignore ignore patterns of global executable file
- logs directory: log directory
- objects directory: stores all the content
- refs directory: storing data points (branches) of the commit pointer
- config file contains your project-specific configuration options
- description file only GitWeb program
- HEAD file pointing to the current branch
5.3 Setting the signature information
- Role: identity information only to distinguish the different developer
- format:
Username: mengxuegu
Email: [email protected]
- note:
Here's signature information and login to the remote database account and password does not have any relationship (code cloud, Github)
- command:
- Project-level / warehouse level: only valid within the scope of the current local Git repository directory
- git config user.name mengxuegu_pro
- git config user.email [email protected]
- Signature information stored location: ./.git/config file
- System user levels: User login scope of the current operating system
- git config --global user.name mengxuegu_glo
- git config --global user.email [email protected]
- Signature information storage location: ~ / .gitconfig
- The level of priority:
- The principle of proximity: the project level override system user level
- If only the system user-level signature, the signature using system-level user information
- Neither existence is not allowed.
5.4 Git basic operations
5.4.1 View Status
- State used to view the work area, staging area
$ git status On branch master # default on the master (trunk) branch No commits yet # no current submission nothing to commit (create/copy files and use "git add" to track) # There is no need to submit (create / copy the files, use "git add" command traceability, it is to use git to manage file)
- According to the state prompted to create a repository demo01.txt file, save some of the content (by i insert content, press: wq to save and exit, press ':! Q' force quit without saving):
$ vim demo01.txt
- Then git status to view the status prompt Untracked files (there is not a trace file):
5.4.2 added to the staging area
- The working area of the "New / Edit" added to the staging area
- Command: git add <file name>
- Recovery, not into the staging area
- 命令: git rm --cached <file name>
5.4.3 submit to the local library
The submission of the staging area to the local library
command: git commit [-m "commit message"] <file name>
modify demo1.txt contents of the file, and then view the status:
5.4.4 View version history
Shows the most detailed information log
command: git log
if the content is too long, multi-screen display Control:
Spacebar: Down View
b: View up
q: Quit view
is displayed in a beautiful format: that each log displays only one line
command: git log --pretty = oneline
simple format:
command: git log --oneline
display version number of steps rollback [recommended]:
command: Git the reflog is
the HEAD @ {corresponding version rollback, many steps need to move the underlying operating}
Version 5.4.5 forward and back
HEAD pointer is moved by the rollback version
based on the index value of the operation [Recommended mode]
command: git reset --hard <local index values>
Example: git reset --hard 64d3d2a
use ^ (XOR) Symbols: only backward
command: Git reset --hard HEAD ^
Note: ^ denotes a step back, n represents a n steps backward
using the symbol ~: only backward
command: git reset --hard HEAD ~ n
NOTE: Specifies the number of steps n, n represents a backward step
5.4.6 Delete files and restore
Prerequisite: Before you delete a file, the file needs to have submitted local library before they can recover
deleted: rm filename .txt
command: git reset --hard <historical index values>
delete operation has been submitted to the local library: pointer to point to the location history record
delete operation has not submitted to the local library: unable to recover
5.4.7 Contrast the difference file
The workspace file and compare the staging area
command: git diff <filename>
Example: add two lines to apply.txt file, use git diff apple.txt view
the workspace files and local history library Compare
command: git diff <local history library version> <file name>
For example: file name without comparing multiple files __