1. The theoretical basis of git
1. What is git
Git is an open source distributed version control system that can effectively and quickly handle the version management of projects from very small to very large
2.git core framework
The working area (Working Directory) is where you usually store the project code.
The staging area (Stage) is used to temporarily store your changes. In fact, it is just a file that saves the list of files to be submitted.
The Git repository (Repository) is a safe place to store data, where you have all the versions of data you submitted. Among them, HEAD points to the latest version put into the warehouse (to be precise, it should be the version pointed to by HEAD in the Git warehouse).
3.git workflow
1) Add and modify files in the working directory;
2) Put the files that need version management into the temporary storage area;
3) Submit the files in the temporary storage area to the Git warehouse.
Therefore, the files managed by Git have three states: modified, staged, and committed, corresponding to each process above in turn.
Two, git operation
In Git, HEAD is used to indicate the current version in the warehouse , HEAD~ is used to indicate the previous version, and HEAD~3 is used to indicate the previous version.
git command | Corresponding execution operation |
---|---|
git init | Initialize git |
git add README.md | Add README.md to the staging area |
git commit -m “add a README.md file” | Add "add a README.md file" to the record |
git clone https://github.com/hasura/graphql-engine | Clone the warehouse under the target URL to the local |
git status | View the status of the current command |
git reset HEAD~ | Roll back the last snapshot pointed to by HEAD to the staging area (that is, the second and third trees are affected) |
git checkout | Overwrite the old version of the temporary storage area with the new version of the working directory (dangerous operation: equivalent to discarding the modification of the working directory) |
git commit -am “change the LICENSE file” | Add all "tracked" files in the working directory to the staging area first, and then execute the commit command |
git log | View historical submissions |
go reflog | View historical operations |
git reset --soft HEAD~ | Only move the HEAD to change the warehouse without changing the staging area. That is, the last commit (commit) is withdrawn, only affecting the third tree |
git reset --hard HEAD~ | Roll back the last snapshot pointed to by HEAD to the staging area, and restore the staging area to the working directory (that is, the first, second, and third trees are affected) |
When we created the Git repository, Git automatically created the only master branch for us, so now, git commit is to submit changes to the master branch. It can be simply understood that all the file modifications that need to be submitted are put in the temporary storage area, and then all the modifications to the temporary storage area are submitted at once.
Note: Use type README.md to view the file (Linux is cat)