source link:https://git-scm.com/book/en/v2/Getting-Started-Git-Basics
1.Snapshots of git
image.pngWith Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
Git thinks about its data more like a stream of snapshots
1.1 why git is so fast?
Nearly Every Operation Is Local
Most operations in Git need only local files and resources to operate — generally no information is needed from another computer on your network.
Thus->>>>no network latency, and very fast.
(side effect, if not push frequently, there is risk to lose your data)
2.Git can be tampered?
Git Has Integrity
Based on the contents of a file or directory structure in Git, it calculate(SHA1) its hashvalue and store it.
Impossible to hack it.
3.How to protect my code?
Git Generally Only Adds Data
you can lose or mess up changes you haven’t committed yet, but after you commit a snapshot into Git, it is very difficult to lose, especially if you regularly push your database to another repository.
4.The Three States
Working Directory------>Staging area------->.git repository
working directory:is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.
Staging area:is a file, generally contained in your Git directory, that stores information about what will go into your next commit.
Git repository:is where Git stores the metadata and object database for your project.and it is what is copied when you clone a repository from another computer.
5.Why avoid using git GUI?
Try to avoid to use Git GUI: which most implements only a partial subset of Git functionality for simplicity.(maybe good for outsider)
6.Two way to get git repo
git init: you can name a repo at your will where you git clone a project
git clone:git clone <url> projectNameYouDefine.
Some advanced git commends reference:
git branch --list: branchs are listed
git branch -a: shows both local and remote branches
HEAD (i.e. the tip of the current branch).
git branch name: creates a new branch head named <branchname> which points to the current HEAD
git checkout branchName:switch to the new branch
git branch -d :<branchname> will be deleted.
*******git-merge - Join two or more development histories together
Note:Merging one branch to master branch will create a new point.
git merge brancheName:merge the branchName to master.
git merge --abort:can only be run after the merge has resulted in conflicts. will abort the merge process and try to reconstruct the pre-merge state.
网友评论