1. Configure username and password:
git config --global user.email zhen24
git config --global user.name zhen24
2. View user name:
git config --get user.name
3. View the list (use the last one):
List: git config --list --global
Single: git config --get user.name
4. Delete a username:
Multiple need to be specified: git config --global --unset user.name zhen24
One does not need to be specified: git config --global --unset user.name
5. Modify the username:
git config --global user.name zhen
git uses hash to uniquely identify objects
Get the repository:
1、git init
eg:git init first_init
2、git clone http://xxxxx
Three areas: working area (working), staging area (staging), and historical warehouse (history)
git add file name: add files to the temporary storage area eg: add the entire file: git add -A
git commit -m 'Added description': submitted to the temporary storage area
Note: Modify the submission instructions of commit, git commit --amend
git push -u origin master: push the code to the remote end, force the overwrite remote use this: git push -u origin master -f
git status : View the difference between the workspace and the temporary storage area
git mv rename a rename b: rename or move
git rm filename: delete file
git rm --cached file name: delete the file in the temporary storage area
git branch branch name: create branch
git checkout branch name: switch branch
6. Create tags:
git tag tag name hash (default current branch hash)
git tag -a 'tag name' hash (default current branch hash)
7. View tags:
git day
8. View the historical schematic diagram:
git log --oneline --decorate --graph --all
Alias: git config --global alias.lol 'log --online --decorate --graph --all' where lol is an alias
Use afterwards: git lol
9. Save the work of the current branch before switching branches:
git stash save -a 'stash1'
10. View the list of saved branches:
git stash list
11. Restore previously saved content:
git stash pop --index stash@{0}
12. Merge branches:
git merge branchname
13. Abandon the merge:
git merge --abort
git show hash/head: display the latest commit information
git show master first parent commit
git show master^2 second parent commit
14. Show short commits:
git show --format=%T master^2
15. Display complete information: git log
git log -p : output difference information such as each commit
git log --stat : output statistical information about the difference of each commit
git log --oneline : output a single line of information
16. View the historical schematic diagram:
The information referenced by commit shows all the information
git log --oneline --decorate --graph --all
17. Graphical information
Show the difference between the workspace and the staging area: git diff
View the difference between the temporary storage area and the historical submission: git diff --cached [can add hash]
Compare the differences between different commit versions: git diff HEAD HEAD^2 --master.txt
Show word differences:
git diff --color-words
git diff --word-diff
git checkout -- master.txt: Overwrite the contents of the workspace with the contents of the temporary storage area
git reset filename(master.txt): ignore differences
Overwrite the content of the workspace with the historical file: git checkout HEAD -- master.txt
git clean