1. Status check:
Git status You can view the status of your workspace and staging area
- Untracked does not have the file in the staging area
- Modified modified
- Staged storage using Git Add
2. Add operations:
Git add [file name] adds the new/modified workspace to the staging areaCopy the code
3. Submit the operation
Git commit -m "commit message" [file name] Commit the contents of the staging area to the local repositoryCopy the code
4. View historical records
Git log Multi-screen display control space Scroll down b Scroll up Q Exit git log --pretty=online git log --oneline git reflogCopy the code
5. Move forward and back
- 5.1 Operations Based on Index Values [Recommended]
Git reset --hard
- 5.2 the use of
^
Symbol: Backward onlygit reset --hard HEAD^
(means one step back, a few steps back plus a few ^) - 5.3 the use of
~
Symbol: Backward onlygit reset --hard HEAD~n
(Indicates n steps back)
6. Compare the three parameters of the reset command
-
– soft parameter
Move the pointer only in the local library
-
– mixed parameter
Move the HEAD pointer in the local library
Reset the staging area
-
–hard parameter (common)
Move the HEAD pointer in the local library
Reset the staging area
Resetting the workspace
7. Delete the file and retrieve it
Prerequisite: The existing state of the file is committed to the local library before deletion
Git reset –hard
- The delete operation has been committed to the local library: the pointer position points to the history record
- Delete operation not committed to local library: HEAD is used for pointer position
8. File comparison
- Git diff compares files in your workspace with staging
- Git diff [local library historical version] [filename] Compares files in your workspace with local historical versions
- Multiple files can be compared without file names
- Git diff –cached compares the last commit between the cache and the local library
- Git diff HEAD compares the last commit in the workspace with the local one
- Git diff compares the difference between two commits
9. Branch management
- Git branch View local branches
- Git branch -r Displays remote branches
- Git branch Creates a branch
- Git branch -d deletes a branch
- Git checkout: Switch branches
- Git checkout -b create a branch and switch to it
- Git merge Merge branches
- Git branch — Merged To see what branches are merged to the current branch
- Git branch –no-merged Displays what branches are not merged to the current branch
Git remote library alias
Git remote addCopy the code
11. Pull of remote library changes
Git fetch = merge git fetch = merge git fetchCopy the code
12. Push to remote library
Git push [remote repository alias]Copy the code
13. Temporary file storage
-git stash save -a "message" Add changes to stash -git stash drop '<stash@(ID)>' Drop stash -git stash list Check the stash list -git stash Clear Remove all stash - git stash pop '<stash@(ID)>' restore changesCopy the code
14. Undo the operation
- the git checkout - < file > undo the workspace changes - git reset HEAD < file > undo file registers the workspace (no cover) - git reset - (soft | mixed | hard) < HEAD - num > | < commit ID > version backCopy the code
15. Roll back online
Git reflog 2. Git reset --hard [index] 3 Git push -f origin git push -f origin Git reflog creates a new version that is the same as the version you rolled back. Instead of going back to the previous version git reflog [index] 3. Git push origin git push originCopy the code
16. Review documentation
Git help git helpCopy the code