what is Git?
Git is a Distributed Revision Control System......
a persistent Map
- meet SHA1
keys and values
every piece of content has its own SHA1.
image.png
these will be Git's key to store "Apple Pie" in the map.
image.png
到目前为止,我们可以把Git 理解为一张地图,使用key和value来存储内容。但是这个persistent体现在哪里?
- persistent
- first commit
This means Git doesn't yet know what to do with them.
To commit a file I have to put it in the staging area first. Whatever is in the staging area will get into the next commit.
we can add files to the staging area with the git add command.
we can use "git log" to look at the list of existing commits.
what is a commit?
image.png image.png注意,commit 里面有一个tree信息,这个tree是什么?
A tree is a directory stored in Git. The commit is pointing at the root directory of the project.That's what this tree is, the root of the project.
看看tree的SHA1值:
image.png image.png-
versioning
image.png
Most commits have a parent.The very first commit is an exception.
second commit:
image.png
- Tags
A tag is like a label for the current state of the project.
Git 中有两种类型的tag: regular tags and annotated tags.
Annotated tags are the ones that come with a message.To create an annotated tag,you could use the git tag.
- Git Object
- Blobs
- Trees
- Commits
- Annotated Tags
- What Git really is ?
Branches
- what branches really are
Git 一般把branch放在.git文件夹下的refs文件夹中。
Branch is nothing else than a simple reference.
- The Mechanics of the Current Branch
how does git know which is our current branch?
image.pngMastering is moving . HEAD is just coming along for the ride.
使用checkout时发生了两件事:
- The first thing is that Git changes HEAD to point at lisa.
- Git replaced the files and folders in our working area,the working directory,with the files and folders in this commit.
if we add a new commit ,then it will look like:
image.pngRemember that branches are just references to commits.
- Let's Merge!
编辑完冲突文件后,使用git status时,发现这个文件并未被添加到暂存区。
image.pngmerge的时候,在没有冲突的情况下,下面这个最后的步骤是Git自动完成的,但是由于我们存在冲突的情况,在我们解决完所有冲突之后,我们需要手动来执行commit。
image.png这个时候其实不需要给出commit message,Git知道我们在解决冲突的过程中,所以它会自动给我们写上。
image.png我们可以直接退出编辑。
image.pngbefore merge
image.pngafter
image.png- Time Travel for Developers
Git的对象之间相互引用。比如,一个父子commit之前的引用,commit到tree的引用,tree和blob之间的引用。引用基本上看起来都是一样的,但是有两个不同的用处。
- References between commits are used to track history
- All the other references are used to track content.
我想说明的东西是,when I checkout something,Git doesn't care about history. It doesn't look at ways that commits connect to each other. It just cares about trees and blobs. So,if you looking towards from this commit here,then Git forgets about the link to the parent of the commit,and it looks at the tree in the commit and all the objects that can be reached from there. That is the entire state of the project at the time of the commit,a complete snapshot of every file,every folder.Git uses this information to replace the content of your working directory. That's how you travel back and forth in time with Git。It's the whole point of versioning.
image.pngObjects and References
image.pngRules
- the current branch tracks new commits
so if you create a new commit by saying git commit or git merge,then the current branch moves to the new commit. - your working directory is updated automatically. when you move to a commit,for example,with git checkout,git replace the content of your working directory with the content that can be reached from that commit.
- any commit,blob or tree that can not be reached from either a branch,head or a tag is considered dead and can be garbage collected.
网友评论