reference resources: https://www.cnblogs.com/tugenhua0707/p/4050072.html
GIT architecture:
Let's first understand the concepts of Git workspace, staging area and version Library:
- Workspace: it is the directory you can see on the computer.
- Staging area: it is called stage or index in English. It is usually stored in the index file (. git/index) in the. git directory, so we sometimes call the temporary storage area index.
- Version Library: the workspace has a hidden directory. Git, which is not the workspace, but the version Library of Git.
The following figure shows the relationship among workspace, staging area in version library and version Library:
-
In the figure, the left side is the workspace and the right side is the version library. In the version library, the area marked "index" is the stage/index, and the area marked "master" is the directory tree represented by the master branch.
-
In the figure, we can see that "HEAD" is actually a "cursor" pointing to the master branch. Therefore, the place where HEAD appears in the illustrated command can be replaced by master.
-
The area identified by objects in the figure is git's object library, which is actually located in the ". git/objects" directory, which contains various objects and contents created.
-
When the git add command is executed on the file modified (or added) in the workspace, the directory tree of the staging area is updated, and the content of the file modified (or added) in the workspace is written to a new object in the object library, and the ID of the object is recorded in the file index of the staging area.
-
When git commit is performed, the directory tree of the staging area is written to the version Library (Object Library), and the master branch will be updated accordingly. That is, the directory tree pointed to by the master is the directory tree of the staging area at the time of submission.
-
When the git reset HEAD command is executed, the directory tree of the staging area will be overwritten and replaced by the directory tree pointed to by the master branch, but the workspace will not be affected.
-
When the GIT RM -- cached < File > command is executed, the file will be deleted directly from the staging area, and the workspace will not be changed.
-
When the GIT checkout. Or git checkout -- > File > command is executed, the files in the workspace will be replaced with all or the specified files in the staging area. This operation is dangerous and will clear changes in the workspace that have not been added to the staging area.
-
When the GIT checkout HEAD. Or git checkout HEAD < File > command is executed, all or part of the files in the master branch pointed to by HEAD will replace the files in the staging area and the workspace. This command is also dangerous because it clears uncommitted changes not only in the workspace, but also in the staging area.
1 1.Clone remote warehouse to local: git clone Warehouse address 2 3 2.git add . : Add the code under this directory from the workspace to the staging area 4 5 3.git commit -m "Submit": Submit the code of the staging area to the local warehouse 6 7 4.Push local code to remote warehouse: git push 8 9 5.To view the differences between workspace codes and staging areas: git status 10 11 6.Create branch: git branch Branch name 12 13 7.Create a new branch and switch: git checkout -b Branch name 14 15 8.Switch branches: git checkout Branch name (switch to) master Branch: git checkout master) 16 17 9.View local branches: git branch (The branch will have*Mark) 18 19 10.To view local and remote branches: git branch -a 20 21 11.stay master Merge code on branch: git merge Branch name 22 23 12.Delete branch: git branch -d Branch name 24 25 13.Force delete: git branch -D Branch name (required after local deletion if the branch is local or remote) push,To delete a remote branch) 26 27 14.Undo the last code committed to the cache: git reset HEAD file name 28 29 15.Pull all remote branches: git fetch 30 31 16.Fallback to the specified version: git reset --hard commit ID(git relog Found in commit ID Top 7, or git log Found in commit ID) 32 33 git log and git relog Differences between: git log Command can display all submitted version information 34 35 git relog: You can view all operation records of all branches (including those that have been deleted) commit Records and reset (operation of) 36 37 17.Fallback 1 version: git reset --hard HEAD 38 39 18.Conflict resolution:a. git stash(Put the locally modified code into the staging area) 40 41 b.git pull(Pull remote branch content) 42 43 c.git stash apply Staging area ID(Take out the contents of the staging area) 44 45 d.Conflict and resolution: vim Conflicting files, deleting (shortcut keys) DD),Exit save 46 47 e.git add . 48 49 f.git commit -m "Conflict resolution" 50 51 g.git push 52 53 To view the contents of the staging area: git stash list 54 55 Take out the contents of the staging area and delete: git stash pop 56 57 Delete specified staging: git stash drop Staging area ID 58 59 Empty staging: git stash clear 60 61 To view the contents of the staging cache: git stash show 62 63 View the contents of the staging cache in detail: git stash show -p 64 65 Create a new branch from staging: git stash branch Branch name (the contents of the staging area will be discarded) 66 67 19.Comparison file: 68 69 git diff File name (directly compare the different contents of this file and the staging area file in the working directory) 70 71 git diff --cached File name (compare staging and remote warehouse) 72 73 git diff commitID File name (compare working directory and remote warehouse) 74 75 20.Create label: 76 77 git tag -a v1 -m "v1 version online" 78 79 View labels: git tag 80 81 Check the specific contents in the label: git show v1 82 83 Push all tags: git push origin --tags 84 85 Push specified label: git push origin v1 86 87 Delete label: git tag -d v1 88 89 To delete a tag remotely: git push origin --tags 90 91 21. .gitignore File configuration and interpretation: 92 93 #notes 94 95 #Represents ignoring all files ending in. aa 96 97 *.aa 98 99 *.log 100 101 #Represents ignoring the. idea folder 102 103 .idea/ 104 105 #Represents ignoring the ignore file in the root directory 106 107 /.ignore 108 109 #Delegate ignores document/Any under.txt End of file 110 111 document/*.txt 112 113 #All files ending in. txt in the document folder will be ignored 114 115 document/**/*.txt 116 117 #Indicates ignore/dd ,aa/dd File 118 119 **/dd 120 121 #Ignore development documents 122 123 filename 124 125 #The filename file in the document folder is not ignored 126 127 !/document/filename