1. Create a new file. If the git add command is not used to submit it to the staging area, then the file has not been tracked.
2. By configuring the .gitignore file, you can specify the files to be ignored, and the ignored folders will not be submitted to the staging area. So this only works for untracked files.
3.git rm --cached <file>: delete the file from the staging area
4. git rm -f <file>: delete the file from the workspace and staging area
5. git add <file>: commit the contents of the workspace to the staging area
6. git commit -m : Create a commit record based on the content in the staging area, and submit the content in the staging area to the commit area
7. git diff: Compare the differences between the workspace and the staging area
8. git diff --cached [<reference>]: Compare the difference between the staging area and a commit, and compare the difference between the staging area and HEAD by default
9. git reset HEAD <file>: Copy the content in the commit area to the staging area, and the content in the work area will not change
10. git checkout -- <file>: Copy the content in the staging area to the workspace. If the content in the workspace is inconsistent with the content in the staging area, the modifications in the workspace will be discarded.
11.git checkout HEAD -- <file>: Copy the contents of the commit area to the work area and staging area. In this way, the work area and the staging area are the contents of the last submission.
12.git branch <branchName>: create a branch
13.git branch -d <branchName>: delete branch
14.git branch -v: show all branches
15. git checkout -b <branckName>: create and switch branches
16. git reset [--mixed] <commit>: roll back the current branch to a certain version in history (--mixed can be omitted), and copy the contents of this version to the staging area. (master and HEAD pointers will move)
17.git reset --hard <commit>: roll back the current branch to a certain version in history, and copy the contents of this version to the staging area and working directory. (master and HEAD pointers will move)
18. git reset --soft <commit>: roll back the current branch to a certain version in history, the staging area and work area will not change, only the master and HEAD pointers will move
19. The difference between git reset and git checkout. Both git reset and git commit can operate on commit and file
Order | example | Move (HEAD/branch) | illustrate |
---|---|---|---|
git reset [commit] | git reset HEAD^ --soft | Yes Yes | fully fallback to a version |
git reset [file] | git reset HEAD ./test.text | reluctantly | Restore the staging area to the state of the commit area |
git checkout[commit] | git checkout master | whether | Move the HEAD pointer to a commit |
git checkout[file] | git checkout -- ./test.text | reluctantly | Copy the contents of the staging area to the workspace |
20.git stash save: keep the current workspace and staging area
21.git stash list : list all stash
22.git stash apply: restore a previous stash
23.git stash drop: delete a stash
24. git stash pop = git stash + git drop
25. git merge: merge branches
26. git fetch: fetch code from remote branch
27:git pull = git fetch + git merge