Edit multiplayer.txt and secrets.txt
[gitmagic/gitmagic.git] / vi / secrets.txt
blobffeb3678e7e3cdbb55442eb0e51ed54138322458
1 == Các Bí Mật ==
3 We take a peek under the hood and explain how Git performs its miracles. I will skimp over details. For in-depth descriptions refer to http://www.kernel.org/pub/software/scm/git/docs/user-manual.html[the user manual].
5 === Invisibility ===
7 How can Git be so unobtrusive? Aside from occasional commits and merges, you can work as if you were unaware that version control exists. That is, until you need it, and that's when you're glad Git was watching over you the whole time.
9 Other version control systems force you to constantly struggle with red tape and bureaucracy. Permissions of files may be read-only unless you explicitly tell a central server which files you intend to edit. The most basic commands may slow to a crawl as the number of users increases. Work grinds to a halt when the network or the central server goes down.
11 In contrast, Git simply keeps the history of your project in the `.git` directory in your working directory. This is your own copy of the history, so you can stay offline until you want to communicate with others. You have total control over the fate of your files because Git can easily recreate a saved state from `.git` bất kỳ lúc nào.
13 === Tính Toàn vẹn ===
15 Phần lớn mọi người sử dụng phương pháp mã hóa để giữ cho thông tin của mình không bị nhòm ngó, nhưng có thứ quan trọng không kém đó là giữ cho thông tin của mình được an toàn. Proper use of cryptographic hash functions có thể ngăn ngừa accidental or malicious data corruption.
17 A SHA1 hash can be thought of as a là một số định danh 160-bit không trùng lắp cho mỗi chuỗi ký tự you'll encounter in your life. Actually more than that: every string of bytes that any human will ever use over many lifetimes.
19 As a SHA1 hash is itself a string of bytes, we can hash strings of bytes containing other hashes. This simple observation is surprisingly useful: look up 'hash chains'. We'll later see how Git uses it to efficiently guarantee data integrity.
21 Briefly, Git keeps your data in the `.git/objects` subdirectory, where instead of normal filenames, you'll find only IDs. By using IDs as filenames, as well as a few lockfiles and timestamping tricks, Git transforms any humble filesystem into an efficient and robust database.
23 === Thông Mính===
25 Làm thể nào mà Git biết bạn đã đổi tên một tệp tin, dù là bạn chẳng bao giờ đề cập đến thực tế này the fact explicitly? Chắc chắn rồi, you may have run *git mv*, but that is exactly the same as a *git rm* followed by a *git add*.
27 Git heuristically ferrets out renames and copies between successive versions. Trên thực tế, nó có thể tìm ra từng đoạn mã nguồn đã bị di chuyển hay sao chép giữa các tệp tin! Though it cannot cover all cases, it does a decent job, and this feature is always improving. If it fails to work for you, try options enabling more expensive copy detection, and consider upgrading.
29 === Indexing ===
31 For every tracked file, Git ghi lại các thông tin như là kích thước, thời gian tạo và lần cuối sửa đổi trong một tệp tin được biết đến là một mục lục 'index'. To determine whether a file has changed, Git compares its current stats with those cached in the index. Nếu chúng giống nhau, thế thì Git có thể bỏ qua việc đọc tệp tin đó lại lần nữa.
33 Since stat calls are considerably faster than file reads, if you only edit a
34 few files, Git can update its state in almost no time.
36 We stated earlier that the index is a staging area. Why is a bunch of file
37 stats a staging area? Because the add command puts files into Git's database
38 and updates these stats, while the commit command, without options, creates a
39 commit based only on these stats and the files already in the database.
41 === Git's Origins ===
43 http://lkml.org/lkml/2005/4/6/121[Linux Kernel Mailing List post] này describes the chain of events that led to Git. The entire thread is a fascinating archaeological site for Git historians.
45 === The Object Database ===
47 Every version of your data is kept in the 'object database', which lives in the
48 subdirectory `.git/objects`; the other residents of `.git/` hold lesser data:
49 the index, branch names, tags, configuration options, logs, the current
50 location of the head commit, and so on. The object database is elementary yet
51 elegant, and the source of Git's power.
53 Mỗi tệp tin trong `.git/objects` là một 'đối tượng'. Ở đây có 3 loại đối tượng
54 that concern us: đối tượng 'blob', đối tượng 'tree', và đối tượng 'commit'.
56 === Blobs ===
58 First, a magic trick. Pick a filename, any filename. Trong một thư mục rỗng:
60  $ echo sweet > YOUR_FILENAME
61  $ git init
62  $ git add .
63  $ find .git/objects -type f
65 Bạn sẽ thấy +.git/objects/aa/823728ea7d592acc69b36875a482cdf3fd5c8d+.
67 How do I know this without knowing the filename? Đó là bởi vì đó là giá trị
68 băm SHA1 của:
70  "blob" SP "6" NUL "sweet" LF
72 là aa823728ea7d592acc69b36875a482cdf3fd5c8d,
73 với SP là khoảng trắng, NUL là byte có giá trị bằng 0 và LF ký tự xuống dòng. Bạn có thể xác minh lại
74 bằng lệnh sau:
76   $ printf "blob 6\000sweet\n" | sha1sum
78 Git is 'content-addressable': tệp tin không được lưu trữ như theo tên của chúng,
79 but rather by the hash of the data they contain, trong tệp tin chúng ta gọi là một in a file we call a 'blob
80 object'. We can think of the hash as a unique ID for a file's contents, so
81 in a sense we are addressing files by their content. Phần khởi đầu `blob 6` đơn thuần
82 chỉ là phần đầu của một merely a header consisting of the object type and its length in bytes; it
83 simplifies internal bookkeeping.
85 Thus I could easily predict what you would see. The file's name is irrelevant:
86 only the data inside is used to construct the blob object.
88 You may be wondering what happens to identical files. Try adding copies of
89 your file, with any filenames whatsoever. The contents of +.git/objects+ stay
90 the same no matter how many you add. Git only stores the data once.
92 By the way, the files within +.git/objects+ are compressed with zlib so you
93 should not stare at them directly. Filter them through
94 http://www.zlib.net/zpipe.c[zpipe -d], hay gõ:
96  $ git cat-file -p aa823728ea7d592acc69b36875a482cdf3fd5c8d
98 which pretty-prints the given object.
100 === Trees ===
102 Nhưng mà tên tệp tin ở đâu? Chúng phải được lưu giữ ở đâu đó chứ.
103 Git gets around to the filenames during a commit:
105  $ git commit  # Type some message.
106  $ find .git/objects -type f
108 You should now see 3 objects. This time I cannot tell you what the 2 new files are, as it partly depends on the filename you picked. We'll proceed assuming you chose ``rose''. If you didn't, you can rewrite history to make it look like you did:
110  $ git filter-branch --tree-filter 'mv YOUR_FILENAME rose'
111  $ find .git/objects -type f
113 Now you should see the file
114 +.git/objects/05/b217bb859794d08bb9e4f7f04cbda4b207fbe9+, bởi vì đây là giá trị băm
115 SHA1 của nội dung của nó:
117  "tree" SP "32" NUL "100644 rose" NUL 0xaa823728ea7d592acc69b36875a482cdf3fd5c8d
119 Check this file does indeed contain the above by typing:
121  $ echo 05b217bb859794d08bb9e4f7f04cbda4b207fbe9 | git cat-file --batch
123 Với lệnh zpipe, ta có thể dễ dàng xác thực một giá trị băm:
125  $ zpipe -d < .git/objects/05/b217bb859794d08bb9e4f7f04cbda4b207fbe9 | sha1sum
127 Hash verification is trickier via cat-file because its output contains more
128 than the raw uncompressed object file.
130 This file is a 'tree' object: a list of tuples consisting of a file
131 type, a filename, and a hash. In our example, the file type is 100644, which
132 means `rose` is a normal file, and the hash is the blob object that contains
133 the contents of `rose'. Other possible file types are executables, symlinks or
134 directories. In the last case, the hash points to a tree object.
136 If you ran filter-branch, you'll have old objects you no longer need. Although
137 they will be jettisoned automatically once the grace period expires, we'll
138 delete them now to make our toy example easier to follow:
140  $ rm -r .git/refs/original
141  $ git reflog expire --expire=now --all
142  $ git prune
144 For real projects you should typically avoid commands like this, as you are
145 destroying backups. If you want a clean repository, it is usually best to make
146 a fresh clone. Also, take care when directly manipulating +.git+: what if a Git
147 command is running at the same time, or a sudden power outage occurs?
148 In general, refs should be deleted with *git update-ref -d*,
149 though usually it's safe to remove +refs/original+ by hand.
151 === Commits ===
153 Chúng tôi đã giảng giải cho bạn 2 trong số 3 đối tượng (object). Cái thứ 3 chính là 'commit'. Its
154 contents depend on the commit message as well as the date and time it was
155 created. To match what we have here, we'll have to tweak it a little:
157  $ git commit --amend -m Shakespeare  # Change the commit message.
158  $ git filter-branch --env-filter 'export
159      GIT_AUTHOR_DATE="Fri 13 Feb 2009 15:31:30 -0800"
160      GIT_AUTHOR_NAME="Alice"
161      GIT_AUTHOR_EMAIL="alice@example.com"
162      GIT_COMMITTER_DATE="Fri, 13 Feb 2009 15:31:30 -0800"
163      GIT_COMMITTER_NAME="Bob"
164      GIT_COMMITTER_EMAIL="bob@example.com"'  # Rig timestamps and authors.
165  $ find .git/objects -type f
167 You should now see
168 +.git/objects/49/993fe130c4b3bf24857a15d7969c396b7bc187+
169 which is the SHA1 hash of its contents:
171  "commit 158" NUL
172  "tree 05b217bb859794d08bb9e4f7f04cbda4b207fbe9" LF
173  "author Alice <alice@example.com> 1234567890 -0800" LF
174  "committer Bob <bob@example.com> 1234567890 -0800" LF
175  LF
176  "Shakespeare" LF
178 Như ở phần trước, bạn có thể chạy lệnh zpipe hay cat-file để tự mình trông thấy.
180 Đây là lần commit đầu tiên, do vậy lần commit này không có cha, nhưng những lần commit sau
181 sẽ luôn luôn chứa it nhất là một dòng chỉ định commit cha.
183 === Indistinguishable From Magic ===
185 Git's secrets seem too simple. It looks like you could mix together a few shell scripts and add a dash of C code to cook it up in a matter of hours: a melange of basic filesystem operations and SHA1 hashing, garnished with lock files and fsyncs for robustness. In fact, this accurately describes the earliest versions of Git. Nonetheless, apart from ingenious packing tricks to save space, and ingenious indexing tricks to save time, we now know how Git deftly changes a filesystem into a database perfect for version control.
187 Ví dụ, nếu một tệp tin bất kỳ nào đó trong if any file within the object database is corrupted by a disk
188 error, then its hash will no longer match, điều này sẽ mang lại rắc rối cho chúng ta. By
189 hashing hashes of other objects, chúng ta có thể duy trì tính liêm chính ở tất cả các mức. Commits
190 are atomic, that is, a commit can never only partially record changes: we can
191 only compute the hash of a commit and store it in the database after we already
192 have stored all relevant trees, blobs and parent commits. The object
193 database is immune to unexpected interruptions such as power outages.
195 We defeat even the most devious adversaries. Suppose somebody attempts to
196 stealthily modify the contents of a file in an ancient version of a project. To
197 keep the object database looking healthy, they must also change the hash of the
198 corresponding blob object since it's now a different string of bytes. This
199 means they'll have to change the hash of any tree object referencing the file,
200 and in turn change the hash of all commit objects involving such a tree, in
201 addition to the hashes of all the descendants of these commits. This implies the
202 hash of the official head differs to that of the bad repository. By
203 following the trail of mismatching hashes we can pinpoint the mutilated file,
204 as well as the commit where it was first corrupted.
206 In short, so long as the 20 bytes representing the last commit are safe,
207 it's impossible to tamper with a Git repository.
209 Đặc tính nào của Git là trứ danh nhất? Nhánh? Trộn? Hay Tags?
210 Mere details. The current head được giữ trong tệp tin +.git/HEAD+,
211 which contains a hash of a commit object. The hash gets updated during a commit
212 as well as many other commands. Branches are almost the same: chúng là các tệp tin trong thư mục
213 +.git/refs/heads+. Tags cũng thế: chúng ở tại +.git/refs/tags+ nhưng chúng
214 được cập nhật bởi các lệnh khác nhau.