没有合适的资源?快使用搜索试试~ 我知道了~
Git from the Bottom Up
需积分: 0 6 下载量 19 浏览量
2013-11-17
06:23:04
上传
评论
收藏 792KB PDF 举报
温馨提示
试读
31页
In author's pursuit to understand Git, it’s been helpful for me to understand it from the bottom up — rather than look at it only in terms of its high-level commands. And since Git is so beautifully simple when viewed this way, the author thought others might be interested to read what his found, and perhaps avoid the pain he went through finding it.
资源推荐
资源详情
资源评论
Gi from the bottom up
Wed, Dec
by John Wiegley
In my pursuit to understand Git, it’s been helpful for me to understand it from the bottom
up — rather than look at it only in terms of its high-level commands. And since Git is so beauti-
fully simple when viewed this way, I thought others might be interested to read what I’ve found,
and perhaps avoid the pain I went through finding it.
I used Git version 1.5.4.5 for each of the examples found in this document.
Contents
1. License 2
2. Introduction 3
3. Repository: Directory content tracking 5
Introducing the blob 6
Blobs are stored in trees 7
How trees are made 8
e beauty of commits 10
A commit by any other name… 12
Branching and the power of rebase 15
4. e Index: Meet the middle man 20
Taking the index farther 22
5. To reset, or not to reset 24
Doing a mixed reset 24
Doing a so reset 24
Doing a hard reset 25
6. Last links in the chain: Stashing and the reflog 27
7. Conclusion 30
8. Further reading 31
License
is document is provided under the terms of the Creative Commons Attribution-Share Alike
3.0 United States License, which may be viewed at the following URL:
http://creativecommons.org/licenses/by-sa/3.0/us/
In brief, you may use the contents of this document for any purpose, personal, commercial
or otherwise, so long as attribution to the author is maintained. Likewise, the document may be
modified, and derivative works and translations made available, so long as such modifications
and derivations are offered to the public on equal terms as the original document.
http://www.newartisans.com///git-from-the-bottom-up.html © , John Wiegley
- -
Introduction
Welcome to the world of Git. I hope this document will help to advance your understanding of
this powerful content tracking system, and reveal a bit of the simplicity underlying it — howev-
er dizzying its array of options may seem from the outside.
Before we dive in, there are a few terms which should be mentioned first, since they’ll appear
repeatedly throughout this text:
repository A repository is a collection of commits, each of which is an archive of
what the project's working tree looked like at a past date, whether on
your machine or someone else's. It also defines (see below), which
identifies the branch or commit the current working tree stemmed from.
Lastly, it contains a set of branches and tags, to identify certain commits
by name.
the index Unlike other, similar tools you may have used, Git does not commit
changes directly from the working tree into the repository. Instead,
changes are first registered in something called the index. ink of it as
a way of “confirming” your changes, one by one, before doing a commit
(which records all your approved changes at once). Some find it helpful
to call it instead as the “staging area”, instead of the index.
working tree A working tree is any directory on your filesystem which has a repository
associated with it (typically indicated by the presence of a sub-directory
within it named .git.). It includes all the files and sub-directories in
that directory.
commit A commit is a snapshot of your working tree at some point in time. e
state of (see below) at the time your commit is made becomes that
commit’s parent. is is what creates the notion of a “revision history”.
branch A branch is just a name for a commit (and much more will be said about
commits in a moment), also called a reference. It’s the parentage of a
commit which defines its history, and thus the typical notion of a
“branch of development”.
tag A tag is also a name for a commit, similar to a branch, except that it al-
ways names the same commit, and can have its own description text.
http://www.newartisans.com///git-from-the-bottom-up.html © , John Wiegley
- -
master e mainline of development in most repositories is done on a branch
called “master”. Although this is a typical default, it is in no way special.
is used by your repository to define what is currently checked out:
•
If you checkout a branch, symbolically refers to that branch,
indicating that the branch name should be updated aer the next
commit operation.
•
If you checkout a specific commit, refers to that commit only.
is is referred to as a detached , and occurs, for example, if you
check out a tag name.
e usual flow of events is this: Aer creating a repository, your work is done in the working
tree. Once your work reaches a significant point — the completion of a bug, the end of the
working day, a moment when everything compiles — you add your changes successively to the
index. Once the index contains everything you intend to commit, you record its content in the
repository. Here’s a simple diagram that shows a typical project’s life-cycle:
Index
Repository
Working
Tree
Changes to the working
tree are registered in the
index using git-add
Changes are committed to
the repository from the
state of the index using
git-commit
Earlier states of the working
tree may be checked out
from the repository at any
time using git-checkout
With this basic picture in mind
1
, the following sections shall attempt to describe how each
of these different entities is important to the operation of Git.
1. In reality, a checkout causes contents from the repository to be copied into the index, which is then
written out to the working tree. But since the user never sees this usage of the index during a checkout
operation, I felt it would make more sense not to depict it in the diagram.
http://www.newartisans.com///git-from-the-bottom-up.html © , John Wiegley
- -
Repository: Directory content tracking
As mentioned above, what Git does is quite rudimentary: it maintains snapshots of a directory’s
contents. Much of its internal design can be understood in terms of this basic task.
e design of a Git repository in many ways mirrors the structure of a filesystem: A
filesystem begins with a root directory, which typically consists of other directories, most of
which have leaf nodes, or files, that contain data. Meta-data about these files’ contents is stored
both in the directory (the names), and in the i-nodes that reference the contents of those file
(their size, type, permissions, etc). Each i-node has a unique number that identifies the contents
of its related file. And while you may have many directory entries pointing to a particular i-node
(i.e., hard-links), it’s the i-node which “owns” the contents stored on your filesystem.
Internally, Git shares a strikingly similar structure, albeit with one or two key differences.
First, it represents your file’s contents in blobs, which are also leaf nodes in something awfully
close to a directory, called a tree. Just as an i-node is uniquely identified by a system-assigned
number, a blob is named by computing the hash id of its size and contents. For all intents
and purposes this is just an arbitrary number, like an i-node, except that it has two additional
properties: first, it verifies the blob’s contents will never change; and second, the same contents
shall always be represented by the same blob, no matter where it appears: across commits, across
repositories — even across the whole Internet. If multiple trees reference the same blob, this is
just like hard-linking: the blob will not disappear from your repository as long as there is at least
one link remaining to it.
e difference between a Git blob and a filesystem’s file is that a blob stores no metadata
about its content. All such information is kept in the tree that holds the blob. One tree may
know those contents as a file named “foo” that was created in August 2004, while another tree
may know the same contents as a file named “bar” that was created five years later. In a normal
filesystem, two files with the same contents but with such different metadata would always be
represented as two independent files. Why this difference? Mainly, it’s because a filesystem is
designed to support files that change, whereas Git is not. e fact that data is immutable in the
Git repository is what makes all of this work and so a different design was needed. And as it
turns out, this design allows for much more compact storage, since all objects having identical
content can be shared, no matter where they are.
http://www.newartisans.com///git-from-the-bottom-up.html © , John Wiegley
- -
剩余30页未读,继续阅读
资源评论
coldturnip
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功