How Git Works

2017-08-23  本文已影响12人  细密画红

what is Git?
Git is a Distributed Revision Control System......

a persistent Map

image.png

these will be Git's key to store "Apple Pie" in the map.


image.png

到目前为止,我们可以把Git 理解为一张地图,使用key和value来存储内容。但是这个persistent体现在哪里?

image.png image.png

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

Most commits have a parent.The very first commit is an exception.

second commit:


image.png image.png image.png
  1. Blobs
  2. Trees
  3. Commits
  4. Annotated Tags
image.png

Branches

image.png image.png image.png image.png image.png image.png image.png

Mastering is moving . HEAD is just coming along for the ride.

image.png

使用checkout时发生了两件事:

  1. The first thing is that Git changes HEAD to point at lisa.
  2. Git replaced the files and folders in our working area,the working directory,with the files and folders in this commit.
image.png

if we add a new commit ,then it will look like:

image.png

Remember that branches are just references to commits.

image.png image.png

编辑完冲突文件后,使用git status时,发现这个文件并未被添加到暂存区。

image.png

merge的时候,在没有冲突的情况下,下面这个最后的步骤是Git自动完成的,但是由于我们存在冲突的情况,在我们解决完所有冲突之后,我们需要手动来执行commit。

image.png

这个时候其实不需要给出commit message,Git知道我们在解决冲突的过程中,所以它会自动给我们写上。

image.png

我们可以直接退出编辑。

image.png

before merge

image.png

after

image.png image.png

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.png

Objects and References

image.png
Rules
上一篇 下一篇

猜你喜欢

热点阅读