]>
Commit | Line | Data |
---|---|---|
71f4b183 CW |
1 | Git User's Manual (for version 1.5.1 or newer) |
2 | ______________________________________________ | |
d19fbc3c BF |
3 | |
4 | This manual is designed to be readable by someone with basic unix | |
79c96c57 | 5 | command-line skills, but no previous knowledge of git. |
d19fbc3c | 6 | |
2624d9a5 BF |
7 | <<repositories-and-branches>> and <<exploring-git-history>> explain how |
8 | to fetch and study a project using git--read these chapters to learn how | |
9 | to build and test a particular version of a software project, search for | |
10 | regressions, and so on. | |
ef89f701 | 11 | |
2624d9a5 BF |
12 | People needing to do actual development will also want to read |
13 | <<Developing-with-git>> and <<sharing-development>>. | |
6bd9b682 BF |
14 | |
15 | Further chapters cover more specialized topics. | |
16 | ||
d19fbc3c BF |
17 | Comprehensive reference documentation is available through the man |
18 | pages. For a command such as "git clone", just use | |
19 | ||
20 | ------------------------------------------------ | |
21 | $ man git-clone | |
22 | ------------------------------------------------ | |
23 | ||
2624d9a5 BF |
24 | See also <<git-quick-start>> for a brief overview of git commands, |
25 | without any explanation. | |
ef89f701 | 26 | |
2624d9a5 BF |
27 | Also, see <<todo>> for ways that you can help make this manual more |
28 | complete. | |
ef89f701 | 29 | |
b181d57f | 30 | |
e34caace | 31 | [[repositories-and-branches]] |
d19fbc3c BF |
32 | Repositories and Branches |
33 | ========================= | |
34 | ||
e34caace | 35 | [[how-to-get-a-git-repository]] |
d19fbc3c BF |
36 | How to get a git repository |
37 | --------------------------- | |
38 | ||
39 | It will be useful to have a git repository to experiment with as you | |
40 | read this manual. | |
41 | ||
42 | The best way to get one is by using the gitlink:git-clone[1] command | |
43 | to download a copy of an existing repository for a project that you | |
44 | are interested in. If you don't already have a project in mind, here | |
45 | are some interesting examples: | |
46 | ||
47 | ------------------------------------------------ | |
48 | # git itself (approx. 10MB download): | |
49 | $ git clone git://git.kernel.org/pub/scm/git/git.git | |
50 | # the linux kernel (approx. 150MB download): | |
51 | $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git | |
52 | ------------------------------------------------ | |
53 | ||
54 | The initial clone may be time-consuming for a large project, but you | |
55 | will only need to clone once. | |
56 | ||
57 | The clone command creates a new directory named after the project | |
58 | ("git" or "linux-2.6" in the examples above). After you cd into this | |
59 | directory, you will see that it contains a copy of the project files, | |
60 | together with a special top-level directory named ".git", which | |
61 | contains all the information about the history of the project. | |
62 | ||
d5cd5de4 | 63 | In most of the following, examples will be taken from one of the two |
d19fbc3c BF |
64 | repositories above. |
65 | ||
e34caace | 66 | [[how-to-check-out]] |
d19fbc3c BF |
67 | How to check out a different version of a project |
68 | ------------------------------------------------- | |
69 | ||
70 | Git is best thought of as a tool for storing the history of a | |
71 | collection of files. It stores the history as a compressed | |
72 | collection of interrelated snapshots (versions) of the project's | |
73 | contents. | |
74 | ||
81b6c950 BF |
75 | A single git repository may contain multiple branches. It keeps track |
76 | of them by keeping a list of <<def_head,heads>> which reference the | |
77 | latest version on each branch; the gitlink:git-branch[1] command shows | |
78 | you the list of branch heads: | |
d19fbc3c BF |
79 | |
80 | ------------------------------------------------ | |
81 | $ git branch | |
82 | * master | |
83 | ------------------------------------------------ | |
84 | ||
4f752407 BF |
85 | A freshly cloned repository contains a single branch head, by default |
86 | named "master", with the working directory initialized to the state of | |
87 | the project referred to by that branch head. | |
d19fbc3c | 88 | |
81b6c950 BF |
89 | Most projects also use <<def_tag,tags>>. Tags, like heads, are |
90 | references into the project's history, and can be listed using the | |
d19fbc3c BF |
91 | gitlink:git-tag[1] command: |
92 | ||
93 | ------------------------------------------------ | |
94 | $ git tag -l | |
95 | v2.6.11 | |
96 | v2.6.11-tree | |
97 | v2.6.12 | |
98 | v2.6.12-rc2 | |
99 | v2.6.12-rc3 | |
100 | v2.6.12-rc4 | |
101 | v2.6.12-rc5 | |
102 | v2.6.12-rc6 | |
103 | v2.6.13 | |
104 | ... | |
105 | ------------------------------------------------ | |
106 | ||
fe4b3e59 | 107 | Tags are expected to always point at the same version of a project, |
81b6c950 | 108 | while heads are expected to advance as development progresses. |
fe4b3e59 | 109 | |
81b6c950 | 110 | Create a new branch head pointing to one of these versions and check it |
d19fbc3c BF |
111 | out using gitlink:git-checkout[1]: |
112 | ||
113 | ------------------------------------------------ | |
114 | $ git checkout -b new v2.6.13 | |
115 | ------------------------------------------------ | |
116 | ||
117 | The working directory then reflects the contents that the project had | |
118 | when it was tagged v2.6.13, and gitlink:git-branch[1] shows two | |
119 | branches, with an asterisk marking the currently checked-out branch: | |
120 | ||
121 | ------------------------------------------------ | |
122 | $ git branch | |
123 | master | |
124 | * new | |
125 | ------------------------------------------------ | |
126 | ||
127 | If you decide that you'd rather see version 2.6.17, you can modify | |
128 | the current branch to point at v2.6.17 instead, with | |
129 | ||
130 | ------------------------------------------------ | |
131 | $ git reset --hard v2.6.17 | |
132 | ------------------------------------------------ | |
133 | ||
81b6c950 | 134 | Note that if the current branch head was your only reference to a |
d19fbc3c | 135 | particular point in history, then resetting that branch may leave you |
81b6c950 BF |
136 | with no way to find the history it used to point to; so use this command |
137 | carefully. | |
d19fbc3c | 138 | |
e34caace | 139 | [[understanding-commits]] |
d19fbc3c BF |
140 | Understanding History: Commits |
141 | ------------------------------ | |
142 | ||
143 | Every change in the history of a project is represented by a commit. | |
144 | The gitlink:git-show[1] command shows the most recent commit on the | |
145 | current branch: | |
146 | ||
147 | ------------------------------------------------ | |
148 | $ git show | |
149 | commit 2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2 | |
150 | Author: Jamal Hadi Salim <hadi@cyberus.ca> | |
151 | Date: Sat Dec 2 22:22:25 2006 -0800 | |
152 | ||
153 | [XFRM]: Fix aevent structuring to be more complete. | |
154 | ||
155 | aevents can not uniquely identify an SA. We break the ABI with this | |
156 | patch, but consensus is that since it is not yet utilized by any | |
157 | (known) application then it is fine (better do it now than later). | |
158 | ||
159 | Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca> | |
160 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
161 | ||
162 | diff --git a/Documentation/networking/xfrm_sync.txt b/Documentation/networking/xfrm_sync.txt | |
163 | index 8be626f..d7aac9d 100644 | |
164 | --- a/Documentation/networking/xfrm_sync.txt | |
165 | +++ b/Documentation/networking/xfrm_sync.txt | |
166 | @@ -47,10 +47,13 @@ aevent_id structure looks like: | |
167 | ||
168 | struct xfrm_aevent_id { | |
169 | struct xfrm_usersa_id sa_id; | |
170 | + xfrm_address_t saddr; | |
171 | __u32 flags; | |
172 | + __u32 reqid; | |
173 | }; | |
174 | ... | |
175 | ------------------------------------------------ | |
176 | ||
177 | As you can see, a commit shows who made the latest change, what they | |
178 | did, and why. | |
179 | ||
35121930 BF |
180 | Every commit has a 40-hexdigit id, sometimes called the "object name" or the |
181 | "SHA1 id", shown on the first line of the "git show" output. You can usually | |
182 | refer to a commit by a shorter name, such as a tag or a branch name, but this | |
183 | longer name can also be useful. Most importantly, it is a globally unique | |
184 | name for this commit: so if you tell somebody else the object name (for | |
185 | example in email), then you are guaranteed that name will refer to the same | |
186 | commit in their repository that it does in yours (assuming their repository | |
187 | has that commit at all). Since the object name is computed as a hash over the | |
188 | contents of the commit, you are guaranteed that the commit can never change | |
189 | without its name also changing. | |
190 | ||
191 | In fact, in <<git-internals>> we shall see that everything stored in git | |
192 | history, including file data and directory contents, is stored in an object | |
193 | with a name that is a hash of its contents. | |
d19fbc3c | 194 | |
e34caace | 195 | [[understanding-reachability]] |
d19fbc3c BF |
196 | Understanding history: commits, parents, and reachability |
197 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
198 | ||
199 | Every commit (except the very first commit in a project) also has a | |
200 | parent commit which shows what happened before this commit. | |
201 | Following the chain of parents will eventually take you back to the | |
202 | beginning of the project. | |
203 | ||
204 | However, the commits do not form a simple list; git allows lines of | |
205 | development to diverge and then reconverge, and the point where two | |
206 | lines of development reconverge is called a "merge". The commit | |
207 | representing a merge can therefore have more than one parent, with | |
208 | each parent representing the most recent commit on one of the lines | |
209 | of development leading to that point. | |
210 | ||
211 | The best way to see how this works is using the gitlink:gitk[1] | |
212 | command; running gitk now on a git repository and looking for merge | |
213 | commits will help understand how the git organizes history. | |
214 | ||
215 | In the following, we say that commit X is "reachable" from commit Y | |
216 | if commit X is an ancestor of commit Y. Equivalently, you could say | |
217 | that Y is a descendent of X, or that there is a chain of parents | |
218 | leading from commit Y to commit X. | |
219 | ||
e34caace | 220 | [[history-diagrams]] |
3dff5379 PR |
221 | Understanding history: History diagrams |
222 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
d19fbc3c BF |
223 | |
224 | We will sometimes represent git history using diagrams like the one | |
225 | below. Commits are shown as "o", and the links between them with | |
226 | lines drawn with - / and \. Time goes left to right: | |
227 | ||
1dc71a91 BF |
228 | |
229 | ................................................ | |
d19fbc3c BF |
230 | o--o--o <-- Branch A |
231 | / | |
232 | o--o--o <-- master | |
233 | \ | |
234 | o--o--o <-- Branch B | |
1dc71a91 | 235 | ................................................ |
d19fbc3c BF |
236 | |
237 | If we need to talk about a particular commit, the character "o" may | |
238 | be replaced with another letter or number. | |
239 | ||
e34caace | 240 | [[what-is-a-branch]] |
d19fbc3c BF |
241 | Understanding history: What is a branch? |
242 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
243 | ||
81b6c950 BF |
244 | When we need to be precise, we will use the word "branch" to mean a line |
245 | of development, and "branch head" (or just "head") to mean a reference | |
246 | to the most recent commit on a branch. In the example above, the branch | |
247 | head named "A" is a pointer to one particular commit, but we refer to | |
248 | the line of three commits leading up to that point as all being part of | |
d19fbc3c BF |
249 | "branch A". |
250 | ||
81b6c950 BF |
251 | However, when no confusion will result, we often just use the term |
252 | "branch" both for branches and for branch heads. | |
d19fbc3c | 253 | |
e34caace | 254 | [[manipulating-branches]] |
d19fbc3c BF |
255 | Manipulating branches |
256 | --------------------- | |
257 | ||
258 | Creating, deleting, and modifying branches is quick and easy; here's | |
259 | a summary of the commands: | |
260 | ||
261 | git branch:: | |
262 | list all branches | |
263 | git branch <branch>:: | |
264 | create a new branch named <branch>, referencing the same | |
265 | point in history as the current branch | |
266 | git branch <branch> <start-point>:: | |
267 | create a new branch named <branch>, referencing | |
268 | <start-point>, which may be specified any way you like, | |
269 | including using a branch name or a tag name | |
270 | git branch -d <branch>:: | |
271 | delete the branch <branch>; if the branch you are deleting | |
c64415e2 BF |
272 | points to a commit which is not reachable from the current |
273 | branch, this command will fail with a warning. | |
d19fbc3c BF |
274 | git branch -D <branch>:: |
275 | even if the branch points to a commit not reachable | |
276 | from the current branch, you may know that that commit | |
277 | is still reachable from some other branch or tag. In that | |
278 | case it is safe to use this command to force git to delete | |
279 | the branch. | |
280 | git checkout <branch>:: | |
281 | make the current branch <branch>, updating the working | |
282 | directory to reflect the version referenced by <branch> | |
283 | git checkout -b <new> <start-point>:: | |
284 | create a new branch <new> referencing <start-point>, and | |
285 | check it out. | |
286 | ||
72a76c95 BF |
287 | The special symbol "HEAD" can always be used to refer to the current |
288 | branch. In fact, git uses a file named "HEAD" in the .git directory to | |
289 | remember which branch is current: | |
290 | ||
291 | ------------------------------------------------ | |
292 | $ cat .git/HEAD | |
293 | ref: refs/heads/master | |
294 | ------------------------------------------------ | |
295 | ||
25d9f3fa | 296 | [[detached-head]] |
72a76c95 BF |
297 | Examining an old version without creating a new branch |
298 | ------------------------------------------------------ | |
299 | ||
300 | The git-checkout command normally expects a branch head, but will also | |
301 | accept an arbitrary commit; for example, you can check out the commit | |
302 | referenced by a tag: | |
303 | ||
304 | ------------------------------------------------ | |
305 | $ git checkout v2.6.17 | |
306 | Note: moving to "v2.6.17" which isn't a local branch | |
307 | If you want to create a new branch from this checkout, you may do so | |
308 | (now or later) by using -b with the checkout command again. Example: | |
309 | git checkout -b <new_branch_name> | |
310 | HEAD is now at 427abfa... Linux v2.6.17 | |
311 | ------------------------------------------------ | |
312 | ||
313 | The HEAD then refers to the SHA1 of the commit instead of to a branch, | |
314 | and git branch shows that you are no longer on a branch: | |
315 | ||
316 | ------------------------------------------------ | |
317 | $ cat .git/HEAD | |
318 | 427abfa28afedffadfca9dd8b067eb6d36bac53f | |
953f3d6f | 319 | $ git branch |
72a76c95 BF |
320 | * (no branch) |
321 | master | |
322 | ------------------------------------------------ | |
323 | ||
324 | In this case we say that the HEAD is "detached". | |
325 | ||
953f3d6f BF |
326 | This is an easy way to check out a particular version without having to |
327 | make up a name for the new branch. You can still create a new branch | |
328 | (or tag) for this version later if you decide to. | |
d19fbc3c | 329 | |
e34caace | 330 | [[examining-remote-branches]] |
d19fbc3c BF |
331 | Examining branches from a remote repository |
332 | ------------------------------------------- | |
333 | ||
334 | The "master" branch that was created at the time you cloned is a copy | |
335 | of the HEAD in the repository that you cloned from. That repository | |
336 | may also have had other branches, though, and your local repository | |
337 | keeps branches which track each of those remote branches, which you | |
338 | can view using the "-r" option to gitlink:git-branch[1]: | |
339 | ||
340 | ------------------------------------------------ | |
341 | $ git branch -r | |
342 | origin/HEAD | |
343 | origin/html | |
344 | origin/maint | |
345 | origin/man | |
346 | origin/master | |
347 | origin/next | |
348 | origin/pu | |
349 | origin/todo | |
350 | ------------------------------------------------ | |
351 | ||
352 | You cannot check out these remote-tracking branches, but you can | |
353 | examine them on a branch of your own, just as you would a tag: | |
354 | ||
355 | ------------------------------------------------ | |
356 | $ git checkout -b my-todo-copy origin/todo | |
357 | ------------------------------------------------ | |
358 | ||
359 | Note that the name "origin" is just the name that git uses by default | |
360 | to refer to the repository that you cloned from. | |
361 | ||
362 | [[how-git-stores-references]] | |
f60b9642 BF |
363 | Naming branches, tags, and other references |
364 | ------------------------------------------- | |
d19fbc3c BF |
365 | |
366 | Branches, remote-tracking branches, and tags are all references to | |
f60b9642 BF |
367 | commits. All references are named with a slash-separated path name |
368 | starting with "refs"; the names we've been using so far are actually | |
369 | shorthand: | |
d19fbc3c | 370 | |
f60b9642 BF |
371 | - The branch "test" is short for "refs/heads/test". |
372 | - The tag "v2.6.18" is short for "refs/tags/v2.6.18". | |
373 | - "origin/master" is short for "refs/remotes/origin/master". | |
d19fbc3c | 374 | |
f60b9642 BF |
375 | The full name is occasionally useful if, for example, there ever |
376 | exists a tag and a branch with the same name. | |
d19fbc3c | 377 | |
c64415e2 BF |
378 | As another useful shortcut, the "HEAD" of a repository can be referred |
379 | to just using the name of that repository. So, for example, "origin" | |
380 | is usually a shortcut for the HEAD branch in the repository "origin". | |
d19fbc3c BF |
381 | |
382 | For the complete list of paths which git checks for references, and | |
f60b9642 BF |
383 | the order it uses to decide which to choose when there are multiple |
384 | references with the same shorthand name, see the "SPECIFYING | |
385 | REVISIONS" section of gitlink:git-rev-parse[1]. | |
d19fbc3c BF |
386 | |
387 | [[Updating-a-repository-with-git-fetch]] | |
388 | Updating a repository with git fetch | |
389 | ------------------------------------ | |
390 | ||
391 | Eventually the developer cloned from will do additional work in her | |
392 | repository, creating new commits and advancing the branches to point | |
393 | at the new commits. | |
394 | ||
395 | The command "git fetch", with no arguments, will update all of the | |
396 | remote-tracking branches to the latest version found in her | |
397 | repository. It will not touch any of your own branches--not even the | |
398 | "master" branch that was created for you on clone. | |
399 | ||
e34caace | 400 | [[fetching-branches]] |
d5cd5de4 BF |
401 | Fetching branches from other repositories |
402 | ----------------------------------------- | |
403 | ||
404 | You can also track branches from repositories other than the one you | |
405 | cloned from, using gitlink:git-remote[1]: | |
406 | ||
407 | ------------------------------------------------- | |
408 | $ git remote add linux-nfs git://linux-nfs.org/pub/nfs-2.6.git | |
04483524 | 409 | $ git fetch linux-nfs |
d5cd5de4 BF |
410 | * refs/remotes/linux-nfs/master: storing branch 'master' ... |
411 | commit: bf81b46 | |
412 | ------------------------------------------------- | |
413 | ||
414 | New remote-tracking branches will be stored under the shorthand name | |
415 | that you gave "git remote add", in this case linux-nfs: | |
416 | ||
417 | ------------------------------------------------- | |
418 | $ git branch -r | |
419 | linux-nfs/master | |
420 | origin/master | |
421 | ------------------------------------------------- | |
422 | ||
423 | If you run "git fetch <remote>" later, the tracking branches for the | |
424 | named <remote> will be updated. | |
425 | ||
426 | If you examine the file .git/config, you will see that git has added | |
427 | a new stanza: | |
428 | ||
429 | ------------------------------------------------- | |
430 | $ cat .git/config | |
431 | ... | |
432 | [remote "linux-nfs"] | |
923642fe BF |
433 | url = git://linux-nfs.org/pub/nfs-2.6.git |
434 | fetch = +refs/heads/*:refs/remotes/linux-nfs/* | |
d5cd5de4 BF |
435 | ... |
436 | ------------------------------------------------- | |
437 | ||
fc90c536 BF |
438 | This is what causes git to track the remote's branches; you may modify |
439 | or delete these configuration options by editing .git/config with a | |
440 | text editor. (See the "CONFIGURATION FILE" section of | |
441 | gitlink:git-config[1] for details.) | |
d5cd5de4 | 442 | |
e34caace | 443 | [[exploring-git-history]] |
d19fbc3c BF |
444 | Exploring git history |
445 | ===================== | |
446 | ||
447 | Git is best thought of as a tool for storing the history of a | |
448 | collection of files. It does this by storing compressed snapshots of | |
449 | the contents of a file heirarchy, together with "commits" which show | |
450 | the relationships between these snapshots. | |
451 | ||
452 | Git provides extremely flexible and fast tools for exploring the | |
453 | history of a project. | |
454 | ||
aacd404e | 455 | We start with one specialized tool that is useful for finding the |
d19fbc3c BF |
456 | commit that introduced a bug into a project. |
457 | ||
e34caace | 458 | [[using-bisect]] |
d19fbc3c BF |
459 | How to use bisect to find a regression |
460 | -------------------------------------- | |
461 | ||
462 | Suppose version 2.6.18 of your project worked, but the version at | |
463 | "master" crashes. Sometimes the best way to find the cause of such a | |
464 | regression is to perform a brute-force search through the project's | |
465 | history to find the particular commit that caused the problem. The | |
466 | gitlink:git-bisect[1] command can help you do this: | |
467 | ||
468 | ------------------------------------------------- | |
469 | $ git bisect start | |
470 | $ git bisect good v2.6.18 | |
471 | $ git bisect bad master | |
472 | Bisecting: 3537 revisions left to test after this | |
473 | [65934a9a028b88e83e2b0f8b36618fe503349f8e] BLOCK: Make USB storage depend on SCSI rather than selecting it [try #6] | |
474 | ------------------------------------------------- | |
475 | ||
476 | If you run "git branch" at this point, you'll see that git has | |
477 | temporarily moved you to a new branch named "bisect". This branch | |
478 | points to a commit (with commit id 65934...) that is reachable from | |
479 | v2.6.19 but not from v2.6.18. Compile and test it, and see whether | |
480 | it crashes. Assume it does crash. Then: | |
481 | ||
482 | ------------------------------------------------- | |
483 | $ git bisect bad | |
484 | Bisecting: 1769 revisions left to test after this | |
485 | [7eff82c8b1511017ae605f0c99ac275a7e21b867] i2c-core: Drop useless bitmaskings | |
486 | ------------------------------------------------- | |
487 | ||
488 | checks out an older version. Continue like this, telling git at each | |
489 | stage whether the version it gives you is good or bad, and notice | |
490 | that the number of revisions left to test is cut approximately in | |
491 | half each time. | |
492 | ||
493 | After about 13 tests (in this case), it will output the commit id of | |
494 | the guilty commit. You can then examine the commit with | |
495 | gitlink:git-show[1], find out who wrote it, and mail them your bug | |
496 | report with the commit id. Finally, run | |
497 | ||
498 | ------------------------------------------------- | |
499 | $ git bisect reset | |
500 | ------------------------------------------------- | |
501 | ||
502 | to return you to the branch you were on before and delete the | |
503 | temporary "bisect" branch. | |
504 | ||
505 | Note that the version which git-bisect checks out for you at each | |
506 | point is just a suggestion, and you're free to try a different | |
507 | version if you think it would be a good idea. For example, | |
508 | occasionally you may land on a commit that broke something unrelated; | |
509 | run | |
510 | ||
511 | ------------------------------------------------- | |
04483524 | 512 | $ git bisect visualize |
d19fbc3c BF |
513 | ------------------------------------------------- |
514 | ||
515 | which will run gitk and label the commit it chose with a marker that | |
516 | says "bisect". Chose a safe-looking commit nearby, note its commit | |
517 | id, and check it out with: | |
518 | ||
519 | ------------------------------------------------- | |
520 | $ git reset --hard fb47ddb2db... | |
521 | ------------------------------------------------- | |
522 | ||
523 | then test, run "bisect good" or "bisect bad" as appropriate, and | |
524 | continue. | |
525 | ||
e34caace | 526 | [[naming-commits]] |
d19fbc3c BF |
527 | Naming commits |
528 | -------------- | |
529 | ||
530 | We have seen several ways of naming commits already: | |
531 | ||
d55ae921 | 532 | - 40-hexdigit object name |
d19fbc3c BF |
533 | - branch name: refers to the commit at the head of the given |
534 | branch | |
535 | - tag name: refers to the commit pointed to by the given tag | |
536 | (we've seen branches and tags are special cases of | |
537 | <<how-git-stores-references,references>>). | |
538 | - HEAD: refers to the head of the current branch | |
539 | ||
eb6ae7f4 | 540 | There are many more; see the "SPECIFYING REVISIONS" section of the |
aec053bb | 541 | gitlink:git-rev-parse[1] man page for the complete list of ways to |
d19fbc3c BF |
542 | name revisions. Some examples: |
543 | ||
544 | ------------------------------------------------- | |
d55ae921 | 545 | $ git show fb47ddb2 # the first few characters of the object name |
d19fbc3c BF |
546 | # are usually enough to specify it uniquely |
547 | $ git show HEAD^ # the parent of the HEAD commit | |
548 | $ git show HEAD^^ # the grandparent | |
549 | $ git show HEAD~4 # the great-great-grandparent | |
550 | ------------------------------------------------- | |
551 | ||
552 | Recall that merge commits may have more than one parent; by default, | |
553 | ^ and ~ follow the first parent listed in the commit, but you can | |
554 | also choose: | |
555 | ||
556 | ------------------------------------------------- | |
557 | $ git show HEAD^1 # show the first parent of HEAD | |
558 | $ git show HEAD^2 # show the second parent of HEAD | |
559 | ------------------------------------------------- | |
560 | ||
561 | In addition to HEAD, there are several other special names for | |
562 | commits: | |
563 | ||
564 | Merges (to be discussed later), as well as operations such as | |
565 | git-reset, which change the currently checked-out commit, generally | |
566 | set ORIG_HEAD to the value HEAD had before the current operation. | |
567 | ||
568 | The git-fetch operation always stores the head of the last fetched | |
569 | branch in FETCH_HEAD. For example, if you run git fetch without | |
570 | specifying a local branch as the target of the operation | |
571 | ||
572 | ------------------------------------------------- | |
573 | $ git fetch git://example.com/proj.git theirbranch | |
574 | ------------------------------------------------- | |
575 | ||
576 | the fetched commits will still be available from FETCH_HEAD. | |
577 | ||
578 | When we discuss merges we'll also see the special name MERGE_HEAD, | |
579 | which refers to the other branch that we're merging in to the current | |
580 | branch. | |
581 | ||
aec053bb | 582 | The gitlink:git-rev-parse[1] command is a low-level command that is |
d55ae921 BF |
583 | occasionally useful for translating some name for a commit to the object |
584 | name for that commit: | |
aec053bb BF |
585 | |
586 | ------------------------------------------------- | |
587 | $ git rev-parse origin | |
588 | e05db0fd4f31dde7005f075a84f96b360d05984b | |
589 | ------------------------------------------------- | |
590 | ||
e34caace | 591 | [[creating-tags]] |
d19fbc3c BF |
592 | Creating tags |
593 | ------------- | |
594 | ||
595 | We can also create a tag to refer to a particular commit; after | |
596 | running | |
597 | ||
598 | ------------------------------------------------- | |
04483524 | 599 | $ git tag stable-1 1b2e1d63ff |
d19fbc3c BF |
600 | ------------------------------------------------- |
601 | ||
602 | You can use stable-1 to refer to the commit 1b2e1d63ff. | |
603 | ||
c64415e2 BF |
604 | This creates a "lightweight" tag. If you would also like to include a |
605 | comment with the tag, and possibly sign it cryptographically, then you | |
606 | should create a tag object instead; see the gitlink:git-tag[1] man page | |
607 | for details. | |
d19fbc3c | 608 | |
e34caace | 609 | [[browsing-revisions]] |
d19fbc3c BF |
610 | Browsing revisions |
611 | ------------------ | |
612 | ||
613 | The gitlink:git-log[1] command can show lists of commits. On its | |
614 | own, it shows all commits reachable from the parent commit; but you | |
615 | can also make more specific requests: | |
616 | ||
617 | ------------------------------------------------- | |
618 | $ git log v2.5.. # commits since (not reachable from) v2.5 | |
619 | $ git log test..master # commits reachable from master but not test | |
620 | $ git log master..test # ...reachable from test but not master | |
621 | $ git log master...test # ...reachable from either test or master, | |
622 | # but not both | |
623 | $ git log --since="2 weeks ago" # commits from the last 2 weeks | |
624 | $ git log Makefile # commits which modify Makefile | |
625 | $ git log fs/ # ... which modify any file under fs/ | |
626 | $ git log -S'foo()' # commits which add or remove any file data | |
627 | # matching the string 'foo()' | |
628 | ------------------------------------------------- | |
629 | ||
630 | And of course you can combine all of these; the following finds | |
631 | commits since v2.5 which touch the Makefile or any file under fs: | |
632 | ||
633 | ------------------------------------------------- | |
634 | $ git log v2.5.. Makefile fs/ | |
635 | ------------------------------------------------- | |
636 | ||
637 | You can also ask git log to show patches: | |
638 | ||
639 | ------------------------------------------------- | |
640 | $ git log -p | |
641 | ------------------------------------------------- | |
642 | ||
643 | See the "--pretty" option in the gitlink:git-log[1] man page for more | |
644 | display options. | |
645 | ||
646 | Note that git log starts with the most recent commit and works | |
647 | backwards through the parents; however, since git history can contain | |
3dff5379 | 648 | multiple independent lines of development, the particular order that |
d19fbc3c BF |
649 | commits are listed in may be somewhat arbitrary. |
650 | ||
e34caace | 651 | [[generating-diffs]] |
d19fbc3c BF |
652 | Generating diffs |
653 | ---------------- | |
654 | ||
655 | You can generate diffs between any two versions using | |
656 | gitlink:git-diff[1]: | |
657 | ||
658 | ------------------------------------------------- | |
659 | $ git diff master..test | |
660 | ------------------------------------------------- | |
661 | ||
662 | Sometimes what you want instead is a set of patches: | |
663 | ||
664 | ------------------------------------------------- | |
665 | $ git format-patch master..test | |
666 | ------------------------------------------------- | |
667 | ||
668 | will generate a file with a patch for each commit reachable from test | |
669 | but not from master. Note that if master also has commits which are | |
670 | not reachable from test, then the combined result of these patches | |
671 | will not be the same as the diff produced by the git-diff example. | |
672 | ||
e34caace | 673 | [[viewing-old-file-versions]] |
d19fbc3c BF |
674 | Viewing old file versions |
675 | ------------------------- | |
676 | ||
677 | You can always view an old version of a file by just checking out the | |
678 | correct revision first. But sometimes it is more convenient to be | |
679 | able to view an old version of a single file without checking | |
680 | anything out; this command does that: | |
681 | ||
682 | ------------------------------------------------- | |
683 | $ git show v2.5:fs/locks.c | |
684 | ------------------------------------------------- | |
685 | ||
686 | Before the colon may be anything that names a commit, and after it | |
687 | may be any path to a file tracked by git. | |
688 | ||
e34caace | 689 | [[history-examples]] |
aec053bb BF |
690 | Examples |
691 | -------- | |
692 | ||
46acd3fa BF |
693 | [[counting-commits-on-a-branch]] |
694 | Counting the number of commits on a branch | |
695 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
696 | ||
697 | Suppose you want to know how many commits you've made on "mybranch" | |
698 | since it diverged from "origin": | |
699 | ||
700 | ------------------------------------------------- | |
701 | $ git log --pretty=oneline origin..mybranch | wc -l | |
702 | ------------------------------------------------- | |
703 | ||
704 | Alternatively, you may often see this sort of thing done with the | |
705 | lower-level command gitlink:git-rev-list[1], which just lists the SHA1's | |
706 | of all the given commits: | |
707 | ||
708 | ------------------------------------------------- | |
709 | $ git rev-list origin..mybranch | wc -l | |
710 | ------------------------------------------------- | |
711 | ||
e34caace | 712 | [[checking-for-equal-branches]] |
aec053bb | 713 | Check whether two branches point at the same history |
2f99710c | 714 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
aec053bb BF |
715 | |
716 | Suppose you want to check whether two branches point at the same point | |
717 | in history. | |
718 | ||
719 | ------------------------------------------------- | |
720 | $ git diff origin..master | |
721 | ------------------------------------------------- | |
722 | ||
69f7ad73 BF |
723 | will tell you whether the contents of the project are the same at the |
724 | two branches; in theory, however, it's possible that the same project | |
725 | contents could have been arrived at by two different historical | |
d55ae921 | 726 | routes. You could compare the object names: |
aec053bb BF |
727 | |
728 | ------------------------------------------------- | |
729 | $ git rev-list origin | |
730 | e05db0fd4f31dde7005f075a84f96b360d05984b | |
731 | $ git rev-list master | |
732 | e05db0fd4f31dde7005f075a84f96b360d05984b | |
733 | ------------------------------------------------- | |
734 | ||
69f7ad73 BF |
735 | Or you could recall that the ... operator selects all commits |
736 | contained reachable from either one reference or the other but not | |
737 | both: so | |
aec053bb BF |
738 | |
739 | ------------------------------------------------- | |
740 | $ git log origin...master | |
741 | ------------------------------------------------- | |
742 | ||
743 | will return no commits when the two branches are equal. | |
744 | ||
e34caace | 745 | [[finding-tagged-descendants]] |
b181d57f BF |
746 | Find first tagged version including a given fix |
747 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
aec053bb | 748 | |
69f7ad73 BF |
749 | Suppose you know that the commit e05db0fd fixed a certain problem. |
750 | You'd like to find the earliest tagged release that contains that | |
751 | fix. | |
752 | ||
753 | Of course, there may be more than one answer--if the history branched | |
754 | after commit e05db0fd, then there could be multiple "earliest" tagged | |
755 | releases. | |
756 | ||
757 | You could just visually inspect the commits since e05db0fd: | |
758 | ||
759 | ------------------------------------------------- | |
760 | $ gitk e05db0fd.. | |
761 | ------------------------------------------------- | |
762 | ||
b181d57f BF |
763 | Or you can use gitlink:git-name-rev[1], which will give the commit a |
764 | name based on any tag it finds pointing to one of the commit's | |
765 | descendants: | |
766 | ||
767 | ------------------------------------------------- | |
04483524 | 768 | $ git name-rev --tags e05db0fd |
b181d57f BF |
769 | e05db0fd tags/v1.5.0-rc1^0~23 |
770 | ------------------------------------------------- | |
771 | ||
772 | The gitlink:git-describe[1] command does the opposite, naming the | |
773 | revision using a tag on which the given commit is based: | |
774 | ||
775 | ------------------------------------------------- | |
776 | $ git describe e05db0fd | |
04483524 | 777 | v1.5.0-rc0-260-ge05db0f |
b181d57f BF |
778 | ------------------------------------------------- |
779 | ||
780 | but that may sometimes help you guess which tags might come after the | |
781 | given commit. | |
782 | ||
783 | If you just want to verify whether a given tagged version contains a | |
784 | given commit, you could use gitlink:git-merge-base[1]: | |
785 | ||
786 | ------------------------------------------------- | |
787 | $ git merge-base e05db0fd v1.5.0-rc1 | |
788 | e05db0fd4f31dde7005f075a84f96b360d05984b | |
789 | ------------------------------------------------- | |
790 | ||
791 | The merge-base command finds a common ancestor of the given commits, | |
792 | and always returns one or the other in the case where one is a | |
793 | descendant of the other; so the above output shows that e05db0fd | |
794 | actually is an ancestor of v1.5.0-rc1. | |
795 | ||
796 | Alternatively, note that | |
797 | ||
798 | ------------------------------------------------- | |
4a7979ca | 799 | $ git log v1.5.0-rc1..e05db0fd |
b181d57f BF |
800 | ------------------------------------------------- |
801 | ||
4a7979ca | 802 | will produce empty output if and only if v1.5.0-rc1 includes e05db0fd, |
b181d57f | 803 | because it outputs only commits that are not reachable from v1.5.0-rc1. |
aec053bb | 804 | |
4a7979ca BF |
805 | As yet another alternative, the gitlink:git-show-branch[1] command lists |
806 | the commits reachable from its arguments with a display on the left-hand | |
807 | side that indicates which arguments that commit is reachable from. So, | |
808 | you can run something like | |
809 | ||
810 | ------------------------------------------------- | |
811 | $ git show-branch e05db0fd v1.5.0-rc0 v1.5.0-rc1 v1.5.0-rc2 | |
812 | ! [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if | |
813 | available | |
814 | ! [v1.5.0-rc0] GIT v1.5.0 preview | |
815 | ! [v1.5.0-rc1] GIT v1.5.0-rc1 | |
816 | ! [v1.5.0-rc2] GIT v1.5.0-rc2 | |
817 | ... | |
818 | ------------------------------------------------- | |
819 | ||
820 | then search for a line that looks like | |
821 | ||
822 | ------------------------------------------------- | |
823 | + ++ [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if | |
824 | available | |
825 | ------------------------------------------------- | |
826 | ||
827 | Which shows that e05db0fd is reachable from itself, from v1.5.0-rc1, and | |
828 | from v1.5.0-rc2, but not from v1.5.0-rc0. | |
829 | ||
82c8bf28 BF |
830 | [[making-a-release]] |
831 | Creating a changelog and tarball for a software release | |
832 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
833 | ||
834 | The gitlink:git-archive[1] command can create a tar or zip archive from | |
835 | any version of a project; for example: | |
836 | ||
837 | ------------------------------------------------- | |
838 | $ git archive --format=tar --prefix=project/ HEAD | gzip >latest.tar.gz | |
839 | ------------------------------------------------- | |
840 | ||
841 | will use HEAD to produce a tar archive in which each filename is | |
842 | preceded by "prefix/". | |
843 | ||
844 | If you're releasing a new version of a software project, you may want | |
845 | to simultaneously make a changelog to include in the release | |
846 | announcement. | |
847 | ||
848 | Linus Torvalds, for example, makes new kernel releases by tagging them, | |
849 | then running: | |
850 | ||
851 | ------------------------------------------------- | |
852 | $ release-script 2.6.12 2.6.13-rc6 2.6.13-rc7 | |
853 | ------------------------------------------------- | |
854 | ||
855 | where release-script is a shell script that looks like: | |
856 | ||
857 | ------------------------------------------------- | |
858 | #!/bin/sh | |
859 | stable="$1" | |
860 | last="$2" | |
861 | new="$3" | |
862 | echo "# git tag v$new" | |
863 | echo "git archive --prefix=linux-$new/ v$new | gzip -9 > ../linux-$new.tar.gz" | |
864 | echo "git diff v$stable v$new | gzip -9 > ../patch-$new.gz" | |
865 | echo "git log --no-merges v$new ^v$last > ../ChangeLog-$new" | |
866 | echo "git shortlog --no-merges v$new ^v$last > ../ShortLog" | |
867 | echo "git diff --stat --summary -M v$last v$new > ../diffstat-$new" | |
868 | ------------------------------------------------- | |
869 | ||
870 | and then he just cut-and-pastes the output commands after verifying that | |
871 | they look OK. | |
4a7979ca | 872 | |
e34caace | 873 | [[Developing-with-git]] |
d19fbc3c BF |
874 | Developing with git |
875 | =================== | |
876 | ||
e34caace | 877 | [[telling-git-your-name]] |
d19fbc3c BF |
878 | Telling git your name |
879 | --------------------- | |
880 | ||
881 | Before creating any commits, you should introduce yourself to git. The | |
58c19d1f BF |
882 | easiest way to do so is to make sure the following lines appear in a |
883 | file named .gitconfig in your home directory: | |
d19fbc3c BF |
884 | |
885 | ------------------------------------------------ | |
d19fbc3c BF |
886 | [user] |
887 | name = Your Name Comes Here | |
888 | email = you@yourdomain.example.com | |
d19fbc3c BF |
889 | ------------------------------------------------ |
890 | ||
fc90c536 BF |
891 | (See the "CONFIGURATION FILE" section of gitlink:git-config[1] for |
892 | details on the configuration file.) | |
893 | ||
d19fbc3c | 894 | |
e34caace | 895 | [[creating-a-new-repository]] |
d19fbc3c BF |
896 | Creating a new repository |
897 | ------------------------- | |
898 | ||
899 | Creating a new repository from scratch is very easy: | |
900 | ||
901 | ------------------------------------------------- | |
902 | $ mkdir project | |
903 | $ cd project | |
f1d2b477 | 904 | $ git init |
d19fbc3c BF |
905 | ------------------------------------------------- |
906 | ||
907 | If you have some initial content (say, a tarball): | |
908 | ||
909 | ------------------------------------------------- | |
910 | $ tar -xzvf project.tar.gz | |
911 | $ cd project | |
f1d2b477 | 912 | $ git init |
d19fbc3c BF |
913 | $ git add . # include everything below ./ in the first commit: |
914 | $ git commit | |
915 | ------------------------------------------------- | |
916 | ||
917 | [[how-to-make-a-commit]] | |
ae25c67a | 918 | How to make a commit |
d19fbc3c BF |
919 | -------------------- |
920 | ||
921 | Creating a new commit takes three steps: | |
922 | ||
923 | 1. Making some changes to the working directory using your | |
924 | favorite editor. | |
925 | 2. Telling git about your changes. | |
926 | 3. Creating the commit using the content you told git about | |
927 | in step 2. | |
928 | ||
929 | In practice, you can interleave and repeat steps 1 and 2 as many | |
930 | times as you want: in order to keep track of what you want committed | |
931 | at step 3, git maintains a snapshot of the tree's contents in a | |
932 | special staging area called "the index." | |
933 | ||
01997b4a BF |
934 | At the beginning, the content of the index will be identical to |
935 | that of the HEAD. The command "git diff --cached", which shows | |
936 | the difference between the HEAD and the index, should therefore | |
937 | produce no output at that point. | |
eb6ae7f4 | 938 | |
d19fbc3c BF |
939 | Modifying the index is easy: |
940 | ||
941 | To update the index with the new contents of a modified file, use | |
942 | ||
943 | ------------------------------------------------- | |
944 | $ git add path/to/file | |
945 | ------------------------------------------------- | |
946 | ||
947 | To add the contents of a new file to the index, use | |
948 | ||
949 | ------------------------------------------------- | |
950 | $ git add path/to/file | |
951 | ------------------------------------------------- | |
952 | ||
eb6ae7f4 | 953 | To remove a file from the index and from the working tree, |
d19fbc3c BF |
954 | |
955 | ------------------------------------------------- | |
956 | $ git rm path/to/file | |
957 | ------------------------------------------------- | |
958 | ||
959 | After each step you can verify that | |
960 | ||
961 | ------------------------------------------------- | |
962 | $ git diff --cached | |
963 | ------------------------------------------------- | |
964 | ||
965 | always shows the difference between the HEAD and the index file--this | |
966 | is what you'd commit if you created the commit now--and that | |
967 | ||
968 | ------------------------------------------------- | |
969 | $ git diff | |
970 | ------------------------------------------------- | |
971 | ||
972 | shows the difference between the working tree and the index file. | |
973 | ||
974 | Note that "git add" always adds just the current contents of a file | |
975 | to the index; further changes to the same file will be ignored unless | |
976 | you run git-add on the file again. | |
977 | ||
978 | When you're ready, just run | |
979 | ||
980 | ------------------------------------------------- | |
981 | $ git commit | |
982 | ------------------------------------------------- | |
983 | ||
984 | and git will prompt you for a commit message and then create the new | |
3dff5379 | 985 | commit. Check to make sure it looks like what you expected with |
d19fbc3c BF |
986 | |
987 | ------------------------------------------------- | |
988 | $ git show | |
989 | ------------------------------------------------- | |
990 | ||
991 | As a special shortcut, | |
992 | ||
993 | ------------------------------------------------- | |
994 | $ git commit -a | |
995 | ------------------------------------------------- | |
996 | ||
997 | will update the index with any files that you've modified or removed | |
998 | and create a commit, all in one step. | |
999 | ||
1000 | A number of commands are useful for keeping track of what you're | |
1001 | about to commit: | |
1002 | ||
1003 | ------------------------------------------------- | |
1004 | $ git diff --cached # difference between HEAD and the index; what | |
1005 | # would be commited if you ran "commit" now. | |
1006 | $ git diff # difference between the index file and your | |
1007 | # working directory; changes that would not | |
1008 | # be included if you ran "commit" now. | |
c64415e2 BF |
1009 | $ git diff HEAD # difference between HEAD and working tree; what |
1010 | # would be committed if you ran "commit -a" now. | |
d19fbc3c BF |
1011 | $ git status # a brief per-file summary of the above. |
1012 | ------------------------------------------------- | |
1013 | ||
e34caace | 1014 | [[creating-good-commit-messages]] |
ae25c67a | 1015 | Creating good commit messages |
d19fbc3c BF |
1016 | ----------------------------- |
1017 | ||
1018 | Though not required, it's a good idea to begin the commit message | |
1019 | with a single short (less than 50 character) line summarizing the | |
1020 | change, followed by a blank line and then a more thorough | |
1021 | description. Tools that turn commits into email, for example, use | |
1022 | the first line on the Subject line and the rest of the commit in the | |
1023 | body. | |
1024 | ||
e34caace | 1025 | [[how-to-merge]] |
ae25c67a | 1026 | How to merge |
d19fbc3c BF |
1027 | ------------ |
1028 | ||
1029 | You can rejoin two diverging branches of development using | |
1030 | gitlink:git-merge[1]: | |
1031 | ||
1032 | ------------------------------------------------- | |
1033 | $ git merge branchname | |
1034 | ------------------------------------------------- | |
1035 | ||
1036 | merges the development in the branch "branchname" into the current | |
1037 | branch. If there are conflicts--for example, if the same file is | |
1038 | modified in two different ways in the remote branch and the local | |
1039 | branch--then you are warned; the output may look something like this: | |
1040 | ||
1041 | ------------------------------------------------- | |
fabbd8f6 BF |
1042 | $ git merge next |
1043 | 100% (4/4) done | |
1044 | Auto-merged file.txt | |
d19fbc3c BF |
1045 | CONFLICT (content): Merge conflict in file.txt |
1046 | Automatic merge failed; fix conflicts and then commit the result. | |
1047 | ------------------------------------------------- | |
1048 | ||
1049 | Conflict markers are left in the problematic files, and after | |
1050 | you resolve the conflicts manually, you can update the index | |
1051 | with the contents and run git commit, as you normally would when | |
1052 | creating a new file. | |
1053 | ||
1054 | If you examine the resulting commit using gitk, you will see that it | |
1055 | has two parents, one pointing to the top of the current branch, and | |
1056 | one to the top of the other branch. | |
1057 | ||
d19fbc3c BF |
1058 | [[resolving-a-merge]] |
1059 | Resolving a merge | |
1060 | ----------------- | |
1061 | ||
1062 | When a merge isn't resolved automatically, git leaves the index and | |
1063 | the working tree in a special state that gives you all the | |
1064 | information you need to help resolve the merge. | |
1065 | ||
1066 | Files with conflicts are marked specially in the index, so until you | |
ef561ac7 BF |
1067 | resolve the problem and update the index, gitlink:git-commit[1] will |
1068 | fail: | |
d19fbc3c BF |
1069 | |
1070 | ------------------------------------------------- | |
1071 | $ git commit | |
1072 | file.txt: needs merge | |
1073 | ------------------------------------------------- | |
1074 | ||
ef561ac7 BF |
1075 | Also, gitlink:git-status[1] will list those files as "unmerged", and the |
1076 | files with conflicts will have conflict markers added, like this: | |
1077 | ||
1078 | ------------------------------------------------- | |
1079 | <<<<<<< HEAD:file.txt | |
1080 | Hello world | |
1081 | ======= | |
1082 | Goodbye | |
1083 | >>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt | |
1084 | ------------------------------------------------- | |
1085 | ||
1086 | All you need to do is edit the files to resolve the conflicts, and then | |
1087 | ||
1088 | ------------------------------------------------- | |
1089 | $ git add file.txt | |
1090 | $ git commit | |
1091 | ------------------------------------------------- | |
1092 | ||
1093 | Note that the commit message will already be filled in for you with | |
1094 | some information about the merge. Normally you can just use this | |
1095 | default message unchanged, but you may add additional commentary of | |
1096 | your own if desired. | |
1097 | ||
1098 | The above is all you need to know to resolve a simple merge. But git | |
1099 | also provides more information to help resolve conflicts: | |
1100 | ||
e34caace | 1101 | [[conflict-resolution]] |
ef561ac7 BF |
1102 | Getting conflict-resolution help during a merge |
1103 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
d19fbc3c BF |
1104 | |
1105 | All of the changes that git was able to merge automatically are | |
1106 | already added to the index file, so gitlink:git-diff[1] shows only | |
ef561ac7 | 1107 | the conflicts. It uses an unusual syntax: |
d19fbc3c BF |
1108 | |
1109 | ------------------------------------------------- | |
1110 | $ git diff | |
1111 | diff --cc file.txt | |
1112 | index 802992c,2b60207..0000000 | |
1113 | --- a/file.txt | |
1114 | +++ b/file.txt | |
1115 | @@@ -1,1 -1,1 +1,5 @@@ | |
1116 | ++<<<<<<< HEAD:file.txt | |
1117 | +Hello world | |
1118 | ++======= | |
1119 | + Goodbye | |
1120 | ++>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt | |
1121 | ------------------------------------------------- | |
1122 | ||
1123 | Recall that the commit which will be commited after we resolve this | |
1124 | conflict will have two parents instead of the usual one: one parent | |
1125 | will be HEAD, the tip of the current branch; the other will be the | |
1126 | tip of the other branch, which is stored temporarily in MERGE_HEAD. | |
1127 | ||
ef561ac7 BF |
1128 | During the merge, the index holds three versions of each file. Each of |
1129 | these three "file stages" represents a different version of the file: | |
1130 | ||
1131 | ------------------------------------------------- | |
1132 | $ git show :1:file.txt # the file in a common ancestor of both branches | |
1133 | $ git show :2:file.txt # the version from HEAD, but including any | |
1134 | # nonconflicting changes from MERGE_HEAD | |
1135 | $ git show :3:file.txt # the version from MERGE_HEAD, but including any | |
1136 | # nonconflicting changes from HEAD. | |
1137 | ------------------------------------------------- | |
1138 | ||
1139 | Since the stage 2 and stage 3 versions have already been updated with | |
1140 | nonconflicting changes, the only remaining differences between them are | |
1141 | the important ones; thus gitlink:git-diff[1] can use the information in | |
1142 | the index to show only those conflicts. | |
1143 | ||
1144 | The diff above shows the differences between the working-tree version of | |
1145 | file.txt and the stage 2 and stage 3 versions. So instead of preceding | |
1146 | each line by a single "+" or "-", it now uses two columns: the first | |
1147 | column is used for differences between the first parent and the working | |
1148 | directory copy, and the second for differences between the second parent | |
1149 | and the working directory copy. (See the "COMBINED DIFF FORMAT" section | |
1150 | of gitlink:git-diff-files[1] for a details of the format.) | |
1151 | ||
1152 | After resolving the conflict in the obvious way (but before updating the | |
1153 | index), the diff will look like: | |
d19fbc3c BF |
1154 | |
1155 | ------------------------------------------------- | |
1156 | $ git diff | |
1157 | diff --cc file.txt | |
1158 | index 802992c,2b60207..0000000 | |
1159 | --- a/file.txt | |
1160 | +++ b/file.txt | |
1161 | @@@ -1,1 -1,1 +1,1 @@@ | |
1162 | - Hello world | |
1163 | -Goodbye | |
1164 | ++Goodbye world | |
1165 | ------------------------------------------------- | |
1166 | ||
1167 | This shows that our resolved version deleted "Hello world" from the | |
1168 | first parent, deleted "Goodbye" from the second parent, and added | |
1169 | "Goodbye world", which was previously absent from both. | |
1170 | ||
ef561ac7 BF |
1171 | Some special diff options allow diffing the working directory against |
1172 | any of these stages: | |
1173 | ||
1174 | ------------------------------------------------- | |
1175 | $ git diff -1 file.txt # diff against stage 1 | |
1176 | $ git diff --base file.txt # same as the above | |
1177 | $ git diff -2 file.txt # diff against stage 2 | |
1178 | $ git diff --ours file.txt # same as the above | |
1179 | $ git diff -3 file.txt # diff against stage 3 | |
1180 | $ git diff --theirs file.txt # same as the above. | |
1181 | ------------------------------------------------- | |
1182 | ||
1183 | The gitlink:git-log[1] and gitk[1] commands also provide special help | |
1184 | for merges: | |
d19fbc3c BF |
1185 | |
1186 | ------------------------------------------------- | |
1187 | $ git log --merge | |
ef561ac7 | 1188 | $ gitk --merge |
d19fbc3c BF |
1189 | ------------------------------------------------- |
1190 | ||
ef561ac7 BF |
1191 | These will display all commits which exist only on HEAD or on |
1192 | MERGE_HEAD, and which touch an unmerged file. | |
d19fbc3c | 1193 | |
61d72564 | 1194 | You may also use gitlink:git-mergetool[1], which lets you merge the |
c64415e2 BF |
1195 | unmerged files using external tools such as emacs or kdiff3. |
1196 | ||
ef561ac7 | 1197 | Each time you resolve the conflicts in a file and update the index: |
d19fbc3c BF |
1198 | |
1199 | ------------------------------------------------- | |
1200 | $ git add file.txt | |
d19fbc3c BF |
1201 | ------------------------------------------------- |
1202 | ||
ef561ac7 BF |
1203 | the different stages of that file will be "collapsed", after which |
1204 | git-diff will (by default) no longer show diffs for that file. | |
d19fbc3c BF |
1205 | |
1206 | [[undoing-a-merge]] | |
ae25c67a | 1207 | Undoing a merge |
d19fbc3c BF |
1208 | --------------- |
1209 | ||
1210 | If you get stuck and decide to just give up and throw the whole mess | |
1211 | away, you can always return to the pre-merge state with | |
1212 | ||
1213 | ------------------------------------------------- | |
1214 | $ git reset --hard HEAD | |
1215 | ------------------------------------------------- | |
1216 | ||
1217 | Or, if you've already commited the merge that you want to throw away, | |
1218 | ||
1219 | ------------------------------------------------- | |
1c73bb0e | 1220 | $ git reset --hard ORIG_HEAD |
d19fbc3c BF |
1221 | ------------------------------------------------- |
1222 | ||
1223 | However, this last command can be dangerous in some cases--never | |
1224 | throw away a commit you have already committed if that commit may | |
1225 | itself have been merged into another branch, as doing so may confuse | |
1226 | further merges. | |
1227 | ||
e34caace | 1228 | [[fast-forwards]] |
d19fbc3c BF |
1229 | Fast-forward merges |
1230 | ------------------- | |
1231 | ||
1232 | There is one special case not mentioned above, which is treated | |
1233 | differently. Normally, a merge results in a merge commit, with two | |
1234 | parents, one pointing at each of the two lines of development that | |
1235 | were merged. | |
1236 | ||
59723040 BF |
1237 | However, if the current branch is a descendant of the other--so every |
1238 | commit present in the one is already contained in the other--then git | |
1239 | just performs a "fast forward"; the head of the current branch is moved | |
1240 | forward to point at the head of the merged-in branch, without any new | |
1241 | commits being created. | |
d19fbc3c | 1242 | |
e34caace | 1243 | [[fixing-mistakes]] |
b684f830 BF |
1244 | Fixing mistakes |
1245 | --------------- | |
1246 | ||
1247 | If you've messed up the working tree, but haven't yet committed your | |
1248 | mistake, you can return the entire working tree to the last committed | |
1249 | state with | |
1250 | ||
1251 | ------------------------------------------------- | |
1252 | $ git reset --hard HEAD | |
1253 | ------------------------------------------------- | |
1254 | ||
1255 | If you make a commit that you later wish you hadn't, there are two | |
1256 | fundamentally different ways to fix the problem: | |
1257 | ||
1258 | 1. You can create a new commit that undoes whatever was done | |
1259 | by the previous commit. This is the correct thing if your | |
1260 | mistake has already been made public. | |
1261 | ||
1262 | 2. You can go back and modify the old commit. You should | |
1263 | never do this if you have already made the history public; | |
1264 | git does not normally expect the "history" of a project to | |
1265 | change, and cannot correctly perform repeated merges from | |
1266 | a branch that has had its history changed. | |
1267 | ||
e34caace | 1268 | [[reverting-a-commit]] |
b684f830 BF |
1269 | Fixing a mistake with a new commit |
1270 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1271 | ||
1272 | Creating a new commit that reverts an earlier change is very easy; | |
1273 | just pass the gitlink:git-revert[1] command a reference to the bad | |
1274 | commit; for example, to revert the most recent commit: | |
1275 | ||
1276 | ------------------------------------------------- | |
1277 | $ git revert HEAD | |
1278 | ------------------------------------------------- | |
1279 | ||
1280 | This will create a new commit which undoes the change in HEAD. You | |
1281 | will be given a chance to edit the commit message for the new commit. | |
1282 | ||
1283 | You can also revert an earlier change, for example, the next-to-last: | |
1284 | ||
1285 | ------------------------------------------------- | |
1286 | $ git revert HEAD^ | |
1287 | ------------------------------------------------- | |
1288 | ||
1289 | In this case git will attempt to undo the old change while leaving | |
1290 | intact any changes made since then. If more recent changes overlap | |
1291 | with the changes to be reverted, then you will be asked to fix | |
1292 | conflicts manually, just as in the case of <<resolving-a-merge, | |
1293 | resolving a merge>>. | |
1294 | ||
365aa199 | 1295 | [[fixing-a-mistake-by-editing-history]] |
b684f830 BF |
1296 | Fixing a mistake by editing history |
1297 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1298 | ||
1299 | If the problematic commit is the most recent commit, and you have not | |
1300 | yet made that commit public, then you may just | |
1301 | <<undoing-a-merge,destroy it using git-reset>>. | |
1302 | ||
1303 | Alternatively, you | |
1304 | can edit the working directory and update the index to fix your | |
1305 | mistake, just as if you were going to <<how-to-make-a-commit,create a | |
1306 | new commit>>, then run | |
1307 | ||
1308 | ------------------------------------------------- | |
1309 | $ git commit --amend | |
1310 | ------------------------------------------------- | |
1311 | ||
1312 | which will replace the old commit by a new commit incorporating your | |
1313 | changes, giving you a chance to edit the old commit message first. | |
1314 | ||
1315 | Again, you should never do this to a commit that may already have | |
1316 | been merged into another branch; use gitlink:git-revert[1] instead in | |
1317 | that case. | |
1318 | ||
1319 | It is also possible to edit commits further back in the history, but | |
1320 | this is an advanced topic to be left for | |
1321 | <<cleaning-up-history,another chapter>>. | |
1322 | ||
e34caace | 1323 | [[checkout-of-path]] |
b684f830 BF |
1324 | Checking out an old version of a file |
1325 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1326 | ||
1327 | In the process of undoing a previous bad change, you may find it | |
1328 | useful to check out an older version of a particular file using | |
1329 | gitlink:git-checkout[1]. We've used git checkout before to switch | |
1330 | branches, but it has quite different behavior if it is given a path | |
1331 | name: the command | |
1332 | ||
1333 | ------------------------------------------------- | |
1334 | $ git checkout HEAD^ path/to/file | |
1335 | ------------------------------------------------- | |
1336 | ||
1337 | replaces path/to/file by the contents it had in the commit HEAD^, and | |
1338 | also updates the index to match. It does not change branches. | |
1339 | ||
1340 | If you just want to look at an old version of the file, without | |
1341 | modifying the working directory, you can do that with | |
1342 | gitlink:git-show[1]: | |
1343 | ||
1344 | ------------------------------------------------- | |
ed4eb0d8 | 1345 | $ git show HEAD^:path/to/file |
b684f830 BF |
1346 | ------------------------------------------------- |
1347 | ||
1348 | which will display the given version of the file. | |
1349 | ||
e34caace | 1350 | [[ensuring-good-performance]] |
d19fbc3c BF |
1351 | Ensuring good performance |
1352 | ------------------------- | |
1353 | ||
1354 | On large repositories, git depends on compression to keep the history | |
1355 | information from taking up to much space on disk or in memory. | |
1356 | ||
1357 | This compression is not performed automatically. Therefore you | |
17217090 | 1358 | should occasionally run gitlink:git-gc[1]: |
d19fbc3c BF |
1359 | |
1360 | ------------------------------------------------- | |
1361 | $ git gc | |
1362 | ------------------------------------------------- | |
1363 | ||
17217090 BF |
1364 | to recompress the archive. This can be very time-consuming, so |
1365 | you may prefer to run git-gc when you are not doing other work. | |
d19fbc3c | 1366 | |
e34caace BF |
1367 | |
1368 | [[ensuring-reliability]] | |
11e016a3 BF |
1369 | Ensuring reliability |
1370 | -------------------- | |
1371 | ||
e34caace | 1372 | [[checking-for-corruption]] |
11e016a3 BF |
1373 | Checking the repository for corruption |
1374 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1375 | ||
1191ee18 BF |
1376 | The gitlink:git-fsck[1] command runs a number of self-consistency checks |
1377 | on the repository, and reports on any problems. This may take some | |
21dcb3b7 BF |
1378 | time. The most common warning by far is about "dangling" objects: |
1379 | ||
1380 | ------------------------------------------------- | |
04e50e94 | 1381 | $ git fsck |
21dcb3b7 BF |
1382 | dangling commit 7281251ddd2a61e38657c827739c57015671a6b3 |
1383 | dangling commit 2706a059f258c6b245f298dc4ff2ccd30ec21a63 | |
1384 | dangling commit 13472b7c4b80851a1bc551779171dcb03655e9b5 | |
1385 | dangling blob 218761f9d90712d37a9c5e36f406f92202db07eb | |
1386 | dangling commit bf093535a34a4d35731aa2bd90fe6b176302f14f | |
1387 | dangling commit 8e4bec7f2ddaa268bef999853c25755452100f8e | |
1388 | dangling tree d50bb86186bf27b681d25af89d3b5b68382e4085 | |
1389 | dangling tree b24c2473f1fd3d91352a624795be026d64c8841f | |
1390 | ... | |
1391 | ------------------------------------------------- | |
1392 | ||
59723040 BF |
1393 | Dangling objects are not a problem. At worst they may take up a little |
1394 | extra disk space. They can sometimes provide a last-resort method of | |
1395 | recovery lost work--see <<dangling-objects>> for details. However, if | |
1396 | you want, you may remove them with gitlink:git-prune[1] or the --prune | |
1191ee18 | 1397 | option to gitlink:git-gc[1]: |
21dcb3b7 BF |
1398 | |
1399 | ------------------------------------------------- | |
1400 | $ git gc --prune | |
1401 | ------------------------------------------------- | |
1402 | ||
1191ee18 BF |
1403 | This may be time-consuming. Unlike most other git operations (including |
1404 | git-gc when run without any options), it is not safe to prune while | |
1405 | other git operations are in progress in the same repository. | |
21dcb3b7 | 1406 | |
e34caace | 1407 | [[recovering-lost-changes]] |
11e016a3 BF |
1408 | Recovering lost changes |
1409 | ~~~~~~~~~~~~~~~~~~~~~~~ | |
1410 | ||
e34caace | 1411 | [[reflogs]] |
559e4d7a BF |
1412 | Reflogs |
1413 | ^^^^^^^ | |
1414 | ||
1415 | Say you modify a branch with gitlink:git-reset[1] --hard, and then | |
1416 | realize that the branch was the only reference you had to that point in | |
1417 | history. | |
1418 | ||
1419 | Fortunately, git also keeps a log, called a "reflog", of all the | |
1420 | previous values of each branch. So in this case you can still find the | |
1421 | old history using, for example, | |
1422 | ||
1423 | ------------------------------------------------- | |
1424 | $ git log master@{1} | |
1425 | ------------------------------------------------- | |
1426 | ||
1427 | This lists the commits reachable from the previous version of the head. | |
1428 | This syntax can be used to with any git command that accepts a commit, | |
1429 | not just with git log. Some other examples: | |
1430 | ||
1431 | ------------------------------------------------- | |
1432 | $ git show master@{2} # See where the branch pointed 2, | |
1433 | $ git show master@{3} # 3, ... changes ago. | |
1434 | $ gitk master@{yesterday} # See where it pointed yesterday, | |
1435 | $ gitk master@{"1 week ago"} # ... or last week | |
953f3d6f BF |
1436 | $ git log --walk-reflogs master # show reflog entries for master |
1437 | ------------------------------------------------- | |
1438 | ||
1439 | A separate reflog is kept for the HEAD, so | |
1440 | ||
1441 | ------------------------------------------------- | |
1442 | $ git show HEAD@{"1 week ago"} | |
559e4d7a BF |
1443 | ------------------------------------------------- |
1444 | ||
953f3d6f BF |
1445 | will show what HEAD pointed to one week ago, not what the current branch |
1446 | pointed to one week ago. This allows you to see the history of what | |
1447 | you've checked out. | |
1448 | ||
559e4d7a | 1449 | The reflogs are kept by default for 30 days, after which they may be |
036be17e | 1450 | pruned. See gitlink:git-reflog[1] and gitlink:git-gc[1] to learn |
559e4d7a BF |
1451 | how to control this pruning, and see the "SPECIFYING REVISIONS" |
1452 | section of gitlink:git-rev-parse[1] for details. | |
1453 | ||
1454 | Note that the reflog history is very different from normal git history. | |
1455 | While normal history is shared by every repository that works on the | |
1456 | same project, the reflog history is not shared: it tells you only about | |
1457 | how the branches in your local repository have changed over time. | |
1458 | ||
59723040 | 1459 | [[dangling-object-recovery]] |
559e4d7a BF |
1460 | Examining dangling objects |
1461 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
1462 | ||
59723040 BF |
1463 | In some situations the reflog may not be able to save you. For example, |
1464 | suppose you delete a branch, then realize you need the history it | |
1465 | contained. The reflog is also deleted; however, if you have not yet | |
1466 | pruned the repository, then you may still be able to find the lost | |
1467 | commits in the dangling objects that git-fsck reports. See | |
1468 | <<dangling-objects>> for the details. | |
559e4d7a BF |
1469 | |
1470 | ------------------------------------------------- | |
1471 | $ git fsck | |
1472 | dangling commit 7281251ddd2a61e38657c827739c57015671a6b3 | |
1473 | dangling commit 2706a059f258c6b245f298dc4ff2ccd30ec21a63 | |
1474 | dangling commit 13472b7c4b80851a1bc551779171dcb03655e9b5 | |
1475 | ... | |
1476 | ------------------------------------------------- | |
1477 | ||
aacd404e | 1478 | You can examine |
559e4d7a BF |
1479 | one of those dangling commits with, for example, |
1480 | ||
1481 | ------------------------------------------------ | |
1482 | $ gitk 7281251ddd --not --all | |
1483 | ------------------------------------------------ | |
1484 | ||
1485 | which does what it sounds like: it says that you want to see the commit | |
1486 | history that is described by the dangling commit(s), but not the | |
1487 | history that is described by all your existing branches and tags. Thus | |
1488 | you get exactly the history reachable from that commit that is lost. | |
1489 | (And notice that it might not be just one commit: we only report the | |
1490 | "tip of the line" as being dangling, but there might be a whole deep | |
79c96c57 | 1491 | and complex commit history that was dropped.) |
559e4d7a BF |
1492 | |
1493 | If you decide you want the history back, you can always create a new | |
1494 | reference pointing to it, for example, a new branch: | |
1495 | ||
1496 | ------------------------------------------------ | |
1497 | $ git branch recovered-branch 7281251ddd | |
1498 | ------------------------------------------------ | |
1499 | ||
59723040 BF |
1500 | Other types of dangling objects (blobs and trees) are also possible, and |
1501 | dangling objects can arise in other situations. | |
1502 | ||
11e016a3 | 1503 | |
e34caace | 1504 | [[sharing-development]] |
d19fbc3c | 1505 | Sharing development with others |
b684f830 | 1506 | =============================== |
d19fbc3c BF |
1507 | |
1508 | [[getting-updates-with-git-pull]] | |
1509 | Getting updates with git pull | |
b684f830 | 1510 | ----------------------------- |
d19fbc3c BF |
1511 | |
1512 | After you clone a repository and make a few changes of your own, you | |
1513 | may wish to check the original repository for updates and merge them | |
1514 | into your own work. | |
1515 | ||
1516 | We have already seen <<Updating-a-repository-with-git-fetch,how to | |
1517 | keep remote tracking branches up to date>> with gitlink:git-fetch[1], | |
1518 | and how to merge two branches. So you can merge in changes from the | |
1519 | original repository's master branch with: | |
1520 | ||
1521 | ------------------------------------------------- | |
1522 | $ git fetch | |
1523 | $ git merge origin/master | |
1524 | ------------------------------------------------- | |
1525 | ||
1526 | However, the gitlink:git-pull[1] command provides a way to do this in | |
1527 | one step: | |
1528 | ||
1529 | ------------------------------------------------- | |
1530 | $ git pull origin master | |
1531 | ------------------------------------------------- | |
1532 | ||
1533 | In fact, "origin" is normally the default repository to pull from, | |
1534 | and the default branch is normally the HEAD of the remote repository, | |
1535 | so often you can accomplish the above with just | |
1536 | ||
1537 | ------------------------------------------------- | |
1538 | $ git pull | |
1539 | ------------------------------------------------- | |
1540 | ||
c64415e2 BF |
1541 | See the descriptions of the branch.<name>.remote and branch.<name>.merge |
1542 | options in gitlink:git-config[1] to learn how to control these defaults | |
1543 | depending on the current branch. Also note that the --track option to | |
1544 | gitlink:git-branch[1] and gitlink:git-checkout[1] can be used to | |
1545 | automatically set the default remote branch to pull from at the time | |
1546 | that a branch is created: | |
1547 | ||
1548 | ------------------------------------------------- | |
1549 | $ git checkout --track -b origin/maint maint | |
1550 | ------------------------------------------------- | |
d19fbc3c BF |
1551 | |
1552 | In addition to saving you keystrokes, "git pull" also helps you by | |
1553 | producing a default commit message documenting the branch and | |
1554 | repository that you pulled from. | |
1555 | ||
1556 | (But note that no such commit will be created in the case of a | |
1557 | <<fast-forwards,fast forward>>; instead, your branch will just be | |
79c96c57 | 1558 | updated to point to the latest commit from the upstream branch.) |
d19fbc3c | 1559 | |
1191ee18 BF |
1560 | The git-pull command can also be given "." as the "remote" repository, |
1561 | in which case it just merges in a branch from the current repository; so | |
4c63ff45 BF |
1562 | the commands |
1563 | ||
1564 | ------------------------------------------------- | |
1565 | $ git pull . branch | |
1566 | $ git merge branch | |
1567 | ------------------------------------------------- | |
1568 | ||
1569 | are roughly equivalent. The former is actually very commonly used. | |
1570 | ||
e34caace | 1571 | [[submitting-patches]] |
d19fbc3c | 1572 | Submitting patches to a project |
b684f830 | 1573 | ------------------------------- |
d19fbc3c BF |
1574 | |
1575 | If you just have a few changes, the simplest way to submit them may | |
1576 | just be to send them as patches in email: | |
1577 | ||
036be17e | 1578 | First, use gitlink:git-format-patch[1]; for example: |
d19fbc3c BF |
1579 | |
1580 | ------------------------------------------------- | |
eb6ae7f4 | 1581 | $ git format-patch origin |
d19fbc3c BF |
1582 | ------------------------------------------------- |
1583 | ||
1584 | will produce a numbered series of files in the current directory, one | |
1585 | for each patch in the current branch but not in origin/HEAD. | |
1586 | ||
1587 | You can then import these into your mail client and send them by | |
1588 | hand. However, if you have a lot to send at once, you may prefer to | |
1589 | use the gitlink:git-send-email[1] script to automate the process. | |
1590 | Consult the mailing list for your project first to determine how they | |
1591 | prefer such patches be handled. | |
1592 | ||
e34caace | 1593 | [[importing-patches]] |
d19fbc3c | 1594 | Importing patches to a project |
b684f830 | 1595 | ------------------------------ |
d19fbc3c BF |
1596 | |
1597 | Git also provides a tool called gitlink:git-am[1] (am stands for | |
1598 | "apply mailbox"), for importing such an emailed series of patches. | |
1599 | Just save all of the patch-containing messages, in order, into a | |
1600 | single mailbox file, say "patches.mbox", then run | |
1601 | ||
1602 | ------------------------------------------------- | |
eb6ae7f4 | 1603 | $ git am -3 patches.mbox |
d19fbc3c BF |
1604 | ------------------------------------------------- |
1605 | ||
1606 | Git will apply each patch in order; if any conflicts are found, it | |
1607 | will stop, and you can fix the conflicts as described in | |
01997b4a BF |
1608 | "<<resolving-a-merge,Resolving a merge>>". (The "-3" option tells |
1609 | git to perform a merge; if you would prefer it just to abort and | |
1610 | leave your tree and index untouched, you may omit that option.) | |
1611 | ||
1612 | Once the index is updated with the results of the conflict | |
1613 | resolution, instead of creating a new commit, just run | |
d19fbc3c BF |
1614 | |
1615 | ------------------------------------------------- | |
1616 | $ git am --resolved | |
1617 | ------------------------------------------------- | |
1618 | ||
1619 | and git will create the commit for you and continue applying the | |
1620 | remaining patches from the mailbox. | |
1621 | ||
1622 | The final result will be a series of commits, one for each patch in | |
1623 | the original mailbox, with authorship and commit log message each | |
1624 | taken from the message containing each patch. | |
1625 | ||
1626 | [[setting-up-a-public-repository]] | |
1627 | Setting up a public repository | |
b684f830 | 1628 | ------------------------------ |
d19fbc3c BF |
1629 | |
1630 | Another way to submit changes to a project is to simply tell the | |
1631 | maintainer of that project to pull from your repository, exactly as | |
1632 | you did in the section "<<getting-updates-with-git-pull, Getting | |
1633 | updates with git pull>>". | |
1634 | ||
1635 | If you and maintainer both have accounts on the same machine, then | |
1636 | then you can just pull changes from each other's repositories | |
79c96c57 MC |
1637 | directly; note that all of the commands (gitlink:git-clone[1], |
1638 | git-fetch[1], git-pull[1], etc.) that accept a URL as an argument | |
21f13ee2 | 1639 | will also accept a local directory name; so, for example, you can |
d19fbc3c BF |
1640 | use |
1641 | ||
1642 | ------------------------------------------------- | |
1643 | $ git clone /path/to/repository | |
1644 | $ git pull /path/to/other/repository | |
1645 | ------------------------------------------------- | |
1646 | ||
1647 | If this sort of setup is inconvenient or impossible, another (more | |
1648 | common) option is to set up a public repository on a public server. | |
1649 | This also allows you to cleanly separate private work in progress | |
1650 | from publicly visible work. | |
1651 | ||
1652 | You will continue to do your day-to-day work in your personal | |
1653 | repository, but periodically "push" changes from your personal | |
1654 | repository into your public repository, allowing other developers to | |
1655 | pull from that repository. So the flow of changes, in a situation | |
1656 | where there is one other developer with a public repository, looks | |
1657 | like this: | |
1658 | ||
1659 | you push | |
1660 | your personal repo ------------------> your public repo | |
1661 | ^ | | |
1662 | | | | |
1663 | | you pull | they pull | |
1664 | | | | |
1665 | | | | |
1666 | | they push V | |
1667 | their public repo <------------------- their repo | |
1668 | ||
1669 | Now, assume your personal repository is in the directory ~/proj. We | |
1670 | first create a new clone of the repository: | |
1671 | ||
1672 | ------------------------------------------------- | |
52c80037 | 1673 | $ git clone --bare ~/proj proj.git |
d19fbc3c BF |
1674 | ------------------------------------------------- |
1675 | ||
52c80037 BF |
1676 | The resulting directory proj.git contains a "bare" git repository--it is |
1677 | just the contents of the ".git" directory, without a checked-out copy of | |
1678 | a working directory. | |
d19fbc3c | 1679 | |
c64415e2 | 1680 | Next, copy proj.git to the server where you plan to host the |
d19fbc3c BF |
1681 | public repository. You can use scp, rsync, or whatever is most |
1682 | convenient. | |
1683 | ||
1684 | If somebody else maintains the public server, they may already have | |
1685 | set up a git service for you, and you may skip to the section | |
1686 | "<<pushing-changes-to-a-public-repository,Pushing changes to a public | |
1687 | repository>>", below. | |
1688 | ||
1689 | Otherwise, the following sections explain how to export your newly | |
1690 | created public repository: | |
1691 | ||
1692 | [[exporting-via-http]] | |
1693 | Exporting a git repository via http | |
b684f830 | 1694 | ----------------------------------- |
d19fbc3c BF |
1695 | |
1696 | The git protocol gives better performance and reliability, but on a | |
1697 | host with a web server set up, http exports may be simpler to set up. | |
1698 | ||
1699 | All you need to do is place the newly created bare git repository in | |
1700 | a directory that is exported by the web server, and make some | |
1701 | adjustments to give web clients some extra information they need: | |
1702 | ||
1703 | ------------------------------------------------- | |
1704 | $ mv proj.git /home/you/public_html/proj.git | |
1705 | $ cd proj.git | |
c64415e2 | 1706 | $ git --bare update-server-info |
d19fbc3c BF |
1707 | $ chmod a+x hooks/post-update |
1708 | ------------------------------------------------- | |
1709 | ||
1710 | (For an explanation of the last two lines, see | |
1711 | gitlink:git-update-server-info[1], and the documentation | |
1712 | link:hooks.txt[Hooks used by git].) | |
1713 | ||
1714 | Advertise the url of proj.git. Anybody else should then be able to | |
1715 | clone or pull from that url, for example with a commandline like: | |
1716 | ||
1717 | ------------------------------------------------- | |
1718 | $ git clone http://yourserver.com/~you/proj.git | |
1719 | ------------------------------------------------- | |
1720 | ||
1721 | (See also | |
1722 | link:howto/setup-git-server-over-http.txt[setup-git-server-over-http] | |
1723 | for a slightly more sophisticated setup using WebDAV which also | |
1724 | allows pushing over http.) | |
1725 | ||
1726 | [[exporting-via-git]] | |
1727 | Exporting a git repository via the git protocol | |
b684f830 | 1728 | ----------------------------------------------- |
d19fbc3c BF |
1729 | |
1730 | This is the preferred method. | |
1731 | ||
1732 | For now, we refer you to the gitlink:git-daemon[1] man page for | |
1733 | instructions. (See especially the examples section.) | |
1734 | ||
1735 | [[pushing-changes-to-a-public-repository]] | |
1736 | Pushing changes to a public repository | |
b684f830 | 1737 | -------------------------------------- |
d19fbc3c BF |
1738 | |
1739 | Note that the two techniques outline above (exporting via | |
1740 | <<exporting-via-http,http>> or <<exporting-via-git,git>>) allow other | |
1741 | maintainers to fetch your latest changes, but they do not allow write | |
1742 | access, which you will need to update the public repository with the | |
1743 | latest changes created in your private repository. | |
1744 | ||
1745 | The simplest way to do this is using gitlink:git-push[1] and ssh; to | |
1746 | update the remote branch named "master" with the latest state of your | |
1747 | branch named "master", run | |
1748 | ||
1749 | ------------------------------------------------- | |
1750 | $ git push ssh://yourserver.com/~you/proj.git master:master | |
1751 | ------------------------------------------------- | |
1752 | ||
1753 | or just | |
1754 | ||
1755 | ------------------------------------------------- | |
1756 | $ git push ssh://yourserver.com/~you/proj.git master | |
1757 | ------------------------------------------------- | |
1758 | ||
1759 | As with git-fetch, git-push will complain if this does not result in | |
1760 | a <<fast-forwards,fast forward>>. Normally this is a sign of | |
1761 | something wrong. However, if you are sure you know what you're | |
1762 | doing, you may force git-push to perform the update anyway by | |
1763 | proceeding the branch name by a plus sign: | |
1764 | ||
1765 | ------------------------------------------------- | |
1766 | $ git push ssh://yourserver.com/~you/proj.git +master | |
1767 | ------------------------------------------------- | |
1768 | ||
1769 | As with git-fetch, you may also set up configuration options to | |
1770 | save typing; so, for example, after | |
1771 | ||
1772 | ------------------------------------------------- | |
c64415e2 | 1773 | $ cat >>.git/config <<EOF |
d19fbc3c BF |
1774 | [remote "public-repo"] |
1775 | url = ssh://yourserver.com/~you/proj.git | |
1776 | EOF | |
1777 | ------------------------------------------------- | |
1778 | ||
1779 | you should be able to perform the above push with just | |
1780 | ||
1781 | ------------------------------------------------- | |
1782 | $ git push public-repo master | |
1783 | ------------------------------------------------- | |
1784 | ||
1785 | See the explanations of the remote.<name>.url, branch.<name>.remote, | |
9d13bda3 | 1786 | and remote.<name>.push options in gitlink:git-config[1] for |
d19fbc3c BF |
1787 | details. |
1788 | ||
e34caace | 1789 | [[setting-up-a-shared-repository]] |
d19fbc3c | 1790 | Setting up a shared repository |
b684f830 | 1791 | ------------------------------ |
d19fbc3c BF |
1792 | |
1793 | Another way to collaborate is by using a model similar to that | |
1794 | commonly used in CVS, where several developers with special rights | |
1795 | all push to and pull from a single shared repository. See | |
1796 | link:cvs-migration.txt[git for CVS users] for instructions on how to | |
1797 | set this up. | |
1798 | ||
e34caace | 1799 | [[setting-up-gitweb]] |
b684f830 BF |
1800 | Allow web browsing of a repository |
1801 | ---------------------------------- | |
d19fbc3c | 1802 | |
a8cd1402 BF |
1803 | The gitweb cgi script provides users an easy way to browse your |
1804 | project's files and history without having to install git; see the file | |
04483524 | 1805 | gitweb/INSTALL in the git source tree for instructions on setting it up. |
d19fbc3c | 1806 | |
e34caace | 1807 | [[sharing-development-examples]] |
b684f830 BF |
1808 | Examples |
1809 | -------- | |
d19fbc3c | 1810 | |
9e2163ea BF |
1811 | [[maintaining-topic-branches]] |
1812 | Maintaining topic branches for a Linux subsystem maintainer | |
1813 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1814 | ||
1815 | This describes how Tony Luck uses git in his role as maintainer of the | |
1816 | IA64 architecture for the Linux kernel. | |
1817 | ||
1818 | He uses two public branches: | |
1819 | ||
1820 | - A "test" tree into which patches are initially placed so that they | |
1821 | can get some exposure when integrated with other ongoing development. | |
1822 | This tree is available to Andrew for pulling into -mm whenever he | |
1823 | wants. | |
1824 | ||
1825 | - A "release" tree into which tested patches are moved for final sanity | |
1826 | checking, and as a vehicle to send them upstream to Linus (by sending | |
1827 | him a "please pull" request.) | |
1828 | ||
1829 | He also uses a set of temporary branches ("topic branches"), each | |
1830 | containing a logical grouping of patches. | |
1831 | ||
1832 | To set this up, first create your work tree by cloning Linus's public | |
1833 | tree: | |
1834 | ||
1835 | ------------------------------------------------- | |
1836 | $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git work | |
1837 | $ cd work | |
1838 | ------------------------------------------------- | |
1839 | ||
1840 | Linus's tree will be stored in the remote branch named origin/master, | |
1841 | and can be updated using gitlink:git-fetch[1]; you can track other | |
1842 | public trees using gitlink:git-remote[1] to set up a "remote" and | |
1843 | git-fetch[1] to keep them up-to-date; see <<repositories-and-branches>>. | |
1844 | ||
1845 | Now create the branches in which you are going to work; these start out | |
1846 | at the current tip of origin/master branch, and should be set up (using | |
1847 | the --track option to gitlink:git-branch[1]) to merge changes in from | |
1848 | Linus by default. | |
1849 | ||
1850 | ------------------------------------------------- | |
1851 | $ git branch --track test origin/master | |
1852 | $ git branch --track release origin/master | |
1853 | ------------------------------------------------- | |
1854 | ||
1855 | These can be easily kept up to date using gitlink:git-pull[1] | |
1856 | ||
1857 | ------------------------------------------------- | |
1858 | $ git checkout test && git pull | |
1859 | $ git checkout release && git pull | |
1860 | ------------------------------------------------- | |
1861 | ||
1862 | Important note! If you have any local changes in these branches, then | |
1863 | this merge will create a commit object in the history (with no local | |
1864 | changes git will simply do a "Fast forward" merge). Many people dislike | |
1865 | the "noise" that this creates in the Linux history, so you should avoid | |
1866 | doing this capriciously in the "release" branch, as these noisy commits | |
1867 | will become part of the permanent history when you ask Linus to pull | |
1868 | from the release branch. | |
1869 | ||
1870 | A few configuration variables (see gitlink:git-config[1]) can | |
1871 | make it easy to push both branches to your public tree. (See | |
1872 | <<setting-up-a-public-repository>>.) | |
1873 | ||
1874 | ------------------------------------------------- | |
1875 | $ cat >> .git/config <<EOF | |
1876 | [remote "mytree"] | |
1877 | url = master.kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git | |
1878 | push = release | |
1879 | push = test | |
1880 | EOF | |
1881 | ------------------------------------------------- | |
1882 | ||
1883 | Then you can push both the test and release trees using | |
1884 | gitlink:git-push[1]: | |
1885 | ||
1886 | ------------------------------------------------- | |
1887 | $ git push mytree | |
1888 | ------------------------------------------------- | |
1889 | ||
1890 | or push just one of the test and release branches using: | |
1891 | ||
1892 | ------------------------------------------------- | |
1893 | $ git push mytree test | |
1894 | ------------------------------------------------- | |
1895 | ||
1896 | or | |
1897 | ||
1898 | ------------------------------------------------- | |
1899 | $ git push mytree release | |
1900 | ------------------------------------------------- | |
1901 | ||
1902 | Now to apply some patches from the community. Think of a short | |
1903 | snappy name for a branch to hold this patch (or related group of | |
1904 | patches), and create a new branch from the current tip of Linus's | |
1905 | branch: | |
1906 | ||
1907 | ------------------------------------------------- | |
1908 | $ git checkout -b speed-up-spinlocks origin | |
1909 | ------------------------------------------------- | |
1910 | ||
1911 | Now you apply the patch(es), run some tests, and commit the change(s). If | |
1912 | the patch is a multi-part series, then you should apply each as a separate | |
1913 | commit to this branch. | |
1914 | ||
1915 | ------------------------------------------------- | |
1916 | $ ... patch ... test ... commit [ ... patch ... test ... commit ]* | |
1917 | ------------------------------------------------- | |
1918 | ||
1919 | When you are happy with the state of this change, you can pull it into the | |
1920 | "test" branch in preparation to make it public: | |
1921 | ||
1922 | ------------------------------------------------- | |
1923 | $ git checkout test && git pull . speed-up-spinlocks | |
1924 | ------------------------------------------------- | |
1925 | ||
1926 | It is unlikely that you would have any conflicts here ... but you might if you | |
1927 | spent a while on this step and had also pulled new versions from upstream. | |
1928 | ||
1929 | Some time later when enough time has passed and testing done, you can pull the | |
1930 | same branch into the "release" tree ready to go upstream. This is where you | |
1931 | see the value of keeping each patch (or patch series) in its own branch. It | |
1932 | means that the patches can be moved into the "release" tree in any order. | |
1933 | ||
1934 | ------------------------------------------------- | |
1935 | $ git checkout release && git pull . speed-up-spinlocks | |
1936 | ------------------------------------------------- | |
1937 | ||
1938 | After a while, you will have a number of branches, and despite the | |
1939 | well chosen names you picked for each of them, you may forget what | |
1940 | they are for, or what status they are in. To get a reminder of what | |
1941 | changes are in a specific branch, use: | |
1942 | ||
1943 | ------------------------------------------------- | |
1944 | $ git log linux..branchname | git-shortlog | |
1945 | ------------------------------------------------- | |
1946 | ||
1947 | To see whether it has already been merged into the test or release branches | |
1948 | use: | |
1949 | ||
1950 | ------------------------------------------------- | |
1951 | $ git log test..branchname | |
1952 | ------------------------------------------------- | |
1953 | ||
1954 | or | |
1955 | ||
1956 | ------------------------------------------------- | |
1957 | $ git log release..branchname | |
1958 | ------------------------------------------------- | |
1959 | ||
1960 | (If this branch has not yet been merged you will see some log entries. | |
1961 | If it has been merged, then there will be no output.) | |
1962 | ||
1963 | Once a patch completes the great cycle (moving from test to release, | |
1964 | then pulled by Linus, and finally coming back into your local | |
1965 | "origin/master" branch) the branch for this change is no longer needed. | |
1966 | You detect this when the output from: | |
1967 | ||
1968 | ------------------------------------------------- | |
1969 | $ git log origin..branchname | |
1970 | ------------------------------------------------- | |
1971 | ||
1972 | is empty. At this point the branch can be deleted: | |
1973 | ||
1974 | ------------------------------------------------- | |
1975 | $ git branch -d branchname | |
1976 | ------------------------------------------------- | |
1977 | ||
1978 | Some changes are so trivial that it is not necessary to create a separate | |
1979 | branch and then merge into each of the test and release branches. For | |
1980 | these changes, just apply directly to the "release" branch, and then | |
1981 | merge that into the "test" branch. | |
1982 | ||
1983 | To create diffstat and shortlog summaries of changes to include in a "please | |
1984 | pull" request to Linus you can use: | |
1985 | ||
1986 | ------------------------------------------------- | |
1987 | $ git diff --stat origin..release | |
1988 | ------------------------------------------------- | |
1989 | ||
1990 | and | |
1991 | ||
1992 | ------------------------------------------------- | |
1993 | $ git log -p origin..release | git shortlog | |
1994 | ------------------------------------------------- | |
1995 | ||
1996 | Here are some of the scripts that simplify all this even further. | |
1997 | ||
1998 | ------------------------------------------------- | |
1999 | ==== update script ==== | |
2000 | # Update a branch in my GIT tree. If the branch to be updated | |
2001 | # is origin, then pull from kernel.org. Otherwise merge | |
2002 | # origin/master branch into test|release branch | |
2003 | ||
2004 | case "$1" in | |
2005 | test|release) | |
2006 | git checkout $1 && git pull . origin | |
2007 | ;; | |
2008 | origin) | |
2009 | before=$(cat .git/refs/remotes/origin/master) | |
2010 | git fetch origin | |
2011 | after=$(cat .git/refs/remotes/origin/master) | |
2012 | if [ $before != $after ] | |
2013 | then | |
2014 | git log $before..$after | git shortlog | |
2015 | fi | |
2016 | ;; | |
2017 | *) | |
2018 | echo "Usage: $0 origin|test|release" 1>&2 | |
2019 | exit 1 | |
2020 | ;; | |
2021 | esac | |
2022 | ------------------------------------------------- | |
2023 | ||
2024 | ------------------------------------------------- | |
2025 | ==== merge script ==== | |
2026 | # Merge a branch into either the test or release branch | |
2027 | ||
2028 | pname=$0 | |
2029 | ||
2030 | usage() | |
2031 | { | |
2032 | echo "Usage: $pname branch test|release" 1>&2 | |
2033 | exit 1 | |
2034 | } | |
2035 | ||
2036 | if [ ! -f .git/refs/heads/"$1" ] | |
2037 | then | |
2038 | echo "Can't see branch <$1>" 1>&2 | |
2039 | usage | |
2040 | fi | |
2041 | ||
2042 | case "$2" in | |
2043 | test|release) | |
2044 | if [ $(git log $2..$1 | wc -c) -eq 0 ] | |
2045 | then | |
2046 | echo $1 already merged into $2 1>&2 | |
2047 | exit 1 | |
2048 | fi | |
2049 | git checkout $2 && git pull . $1 | |
2050 | ;; | |
2051 | *) | |
2052 | usage | |
2053 | ;; | |
2054 | esac | |
2055 | ------------------------------------------------- | |
2056 | ||
2057 | ------------------------------------------------- | |
2058 | ==== status script ==== | |
2059 | # report on status of my ia64 GIT tree | |
2060 | ||
2061 | gb=$(tput setab 2) | |
2062 | rb=$(tput setab 1) | |
2063 | restore=$(tput setab 9) | |
2064 | ||
2065 | if [ `git rev-list test..release | wc -c` -gt 0 ] | |
2066 | then | |
2067 | echo $rb Warning: commits in release that are not in test $restore | |
2068 | git log test..release | |
2069 | fi | |
2070 | ||
2071 | for branch in `ls .git/refs/heads` | |
2072 | do | |
2073 | if [ $branch = test -o $branch = release ] | |
2074 | then | |
2075 | continue | |
2076 | fi | |
2077 | ||
2078 | echo -n $gb ======= $branch ====== $restore " " | |
2079 | status= | |
2080 | for ref in test release origin/master | |
2081 | do | |
2082 | if [ `git rev-list $ref..$branch | wc -c` -gt 0 ] | |
2083 | then | |
2084 | status=$status${ref:0:1} | |
2085 | fi | |
2086 | done | |
2087 | case $status in | |
2088 | trl) | |
2089 | echo $rb Need to pull into test $restore | |
2090 | ;; | |
2091 | rl) | |
2092 | echo "In test" | |
2093 | ;; | |
2094 | l) | |
2095 | echo "Waiting for linus" | |
2096 | ;; | |
2097 | "") | |
2098 | echo $rb All done $restore | |
2099 | ;; | |
2100 | *) | |
2101 | echo $rb "<$status>" $restore | |
2102 | ;; | |
2103 | esac | |
2104 | git log origin/master..$branch | git shortlog | |
2105 | done | |
2106 | ------------------------------------------------- | |
d19fbc3c | 2107 | |
d19fbc3c | 2108 | |
d19fbc3c | 2109 | [[cleaning-up-history]] |
4c63ff45 BF |
2110 | Rewriting history and maintaining patch series |
2111 | ============================================== | |
2112 | ||
2113 | Normally commits are only added to a project, never taken away or | |
2114 | replaced. Git is designed with this assumption, and violating it will | |
2115 | cause git's merge machinery (for example) to do the wrong thing. | |
2116 | ||
2117 | However, there is a situation in which it can be useful to violate this | |
2118 | assumption. | |
2119 | ||
e34caace | 2120 | [[patch-series]] |
4c63ff45 BF |
2121 | Creating the perfect patch series |
2122 | --------------------------------- | |
2123 | ||
2124 | Suppose you are a contributor to a large project, and you want to add a | |
2125 | complicated feature, and to present it to the other developers in a way | |
2126 | that makes it easy for them to read your changes, verify that they are | |
2127 | correct, and understand why you made each change. | |
2128 | ||
b181d57f | 2129 | If you present all of your changes as a single patch (or commit), they |
79c96c57 | 2130 | may find that it is too much to digest all at once. |
4c63ff45 BF |
2131 | |
2132 | If you present them with the entire history of your work, complete with | |
2133 | mistakes, corrections, and dead ends, they may be overwhelmed. | |
2134 | ||
2135 | So the ideal is usually to produce a series of patches such that: | |
2136 | ||
2137 | 1. Each patch can be applied in order. | |
2138 | ||
2139 | 2. Each patch includes a single logical change, together with a | |
2140 | message explaining the change. | |
2141 | ||
2142 | 3. No patch introduces a regression: after applying any initial | |
2143 | part of the series, the resulting project still compiles and | |
2144 | works, and has no bugs that it didn't have before. | |
2145 | ||
2146 | 4. The complete series produces the same end result as your own | |
2147 | (probably much messier!) development process did. | |
2148 | ||
b181d57f BF |
2149 | We will introduce some tools that can help you do this, explain how to |
2150 | use them, and then explain some of the problems that can arise because | |
2151 | you are rewriting history. | |
4c63ff45 | 2152 | |
e34caace | 2153 | [[using-git-rebase]] |
4c63ff45 BF |
2154 | Keeping a patch series up to date using git-rebase |
2155 | -------------------------------------------------- | |
2156 | ||
79c96c57 MC |
2157 | Suppose that you create a branch "mywork" on a remote-tracking branch |
2158 | "origin", and create some commits on top of it: | |
4c63ff45 BF |
2159 | |
2160 | ------------------------------------------------- | |
2161 | $ git checkout -b mywork origin | |
2162 | $ vi file.txt | |
2163 | $ git commit | |
2164 | $ vi otherfile.txt | |
2165 | $ git commit | |
2166 | ... | |
2167 | ------------------------------------------------- | |
2168 | ||
2169 | You have performed no merges into mywork, so it is just a simple linear | |
2170 | sequence of patches on top of "origin": | |
2171 | ||
1dc71a91 | 2172 | ................................................ |
4c63ff45 BF |
2173 | o--o--o <-- origin |
2174 | \ | |
2175 | o--o--o <-- mywork | |
1dc71a91 | 2176 | ................................................ |
4c63ff45 BF |
2177 | |
2178 | Some more interesting work has been done in the upstream project, and | |
2179 | "origin" has advanced: | |
2180 | ||
1dc71a91 | 2181 | ................................................ |
4c63ff45 BF |
2182 | o--o--O--o--o--o <-- origin |
2183 | \ | |
2184 | a--b--c <-- mywork | |
1dc71a91 | 2185 | ................................................ |
4c63ff45 BF |
2186 | |
2187 | At this point, you could use "pull" to merge your changes back in; | |
2188 | the result would create a new merge commit, like this: | |
2189 | ||
1dc71a91 | 2190 | ................................................ |
4c63ff45 BF |
2191 | o--o--O--o--o--o <-- origin |
2192 | \ \ | |
2193 | a--b--c--m <-- mywork | |
1dc71a91 | 2194 | ................................................ |
4c63ff45 BF |
2195 | |
2196 | However, if you prefer to keep the history in mywork a simple series of | |
2197 | commits without any merges, you may instead choose to use | |
2198 | gitlink:git-rebase[1]: | |
2199 | ||
2200 | ------------------------------------------------- | |
2201 | $ git checkout mywork | |
2202 | $ git rebase origin | |
2203 | ------------------------------------------------- | |
2204 | ||
b181d57f BF |
2205 | This will remove each of your commits from mywork, temporarily saving |
2206 | them as patches (in a directory named ".dotest"), update mywork to | |
2207 | point at the latest version of origin, then apply each of the saved | |
2208 | patches to the new mywork. The result will look like: | |
4c63ff45 BF |
2209 | |
2210 | ||
1dc71a91 | 2211 | ................................................ |
4c63ff45 BF |
2212 | o--o--O--o--o--o <-- origin |
2213 | \ | |
2214 | a'--b'--c' <-- mywork | |
1dc71a91 | 2215 | ................................................ |
4c63ff45 | 2216 | |
b181d57f BF |
2217 | In the process, it may discover conflicts. In that case it will stop |
2218 | and allow you to fix the conflicts; after fixing conflicts, use "git | |
2219 | add" to update the index with those contents, and then, instead of | |
2220 | running git-commit, just run | |
4c63ff45 BF |
2221 | |
2222 | ------------------------------------------------- | |
2223 | $ git rebase --continue | |
2224 | ------------------------------------------------- | |
2225 | ||
2226 | and git will continue applying the rest of the patches. | |
2227 | ||
2228 | At any point you may use the --abort option to abort this process and | |
2229 | return mywork to the state it had before you started the rebase: | |
2230 | ||
2231 | ------------------------------------------------- | |
2232 | $ git rebase --abort | |
2233 | ------------------------------------------------- | |
2234 | ||
e34caace | 2235 | [[modifying-one-commit]] |
365aa199 BF |
2236 | Modifying a single commit |
2237 | ------------------------- | |
2238 | ||
2239 | We saw in <<fixing-a-mistake-by-editing-history>> that you can replace the | |
2240 | most recent commit using | |
2241 | ||
2242 | ------------------------------------------------- | |
2243 | $ git commit --amend | |
2244 | ------------------------------------------------- | |
2245 | ||
2246 | which will replace the old commit by a new commit incorporating your | |
2247 | changes, giving you a chance to edit the old commit message first. | |
2248 | ||
2249 | You can also use a combination of this and gitlink:git-rebase[1] to edit | |
2250 | commits further back in your history. First, tag the problematic commit with | |
2251 | ||
2252 | ------------------------------------------------- | |
2253 | $ git tag bad mywork~5 | |
2254 | ------------------------------------------------- | |
2255 | ||
2256 | (Either gitk or git-log may be useful for finding the commit.) | |
2257 | ||
25d9f3fa BF |
2258 | Then check out that commit, edit it, and rebase the rest of the series |
2259 | on top of it (note that we could check out the commit on a temporary | |
2260 | branch, but instead we're using a <<detached-head,detached head>>): | |
365aa199 BF |
2261 | |
2262 | ------------------------------------------------- | |
25d9f3fa | 2263 | $ git checkout bad |
365aa199 BF |
2264 | $ # make changes here and update the index |
2265 | $ git commit --amend | |
25d9f3fa | 2266 | $ git rebase --onto HEAD bad mywork |
365aa199 BF |
2267 | ------------------------------------------------- |
2268 | ||
25d9f3fa BF |
2269 | When you're done, you'll be left with mywork checked out, with the top |
2270 | patches on mywork reapplied on top of your modified commit. You can | |
365aa199 BF |
2271 | then clean up with |
2272 | ||
2273 | ------------------------------------------------- | |
365aa199 BF |
2274 | $ git tag -d bad |
2275 | ------------------------------------------------- | |
2276 | ||
2277 | Note that the immutable nature of git history means that you haven't really | |
2278 | "modified" existing commits; instead, you have replaced the old commits with | |
2279 | new commits having new object names. | |
2280 | ||
e34caace | 2281 | [[reordering-patch-series]] |
4c63ff45 BF |
2282 | Reordering or selecting from a patch series |
2283 | ------------------------------------------- | |
2284 | ||
b181d57f BF |
2285 | Given one existing commit, the gitlink:git-cherry-pick[1] command |
2286 | allows you to apply the change introduced by that commit and create a | |
2287 | new commit that records it. So, for example, if "mywork" points to a | |
2288 | series of patches on top of "origin", you might do something like: | |
2289 | ||
2290 | ------------------------------------------------- | |
2291 | $ git checkout -b mywork-new origin | |
2292 | $ gitk origin..mywork & | |
2293 | ------------------------------------------------- | |
2294 | ||
2295 | And browse through the list of patches in the mywork branch using gitk, | |
2296 | applying them (possibly in a different order) to mywork-new using | |
2297 | cherry-pick, and possibly modifying them as you go using commit | |
2298 | --amend. | |
2299 | ||
2300 | Another technique is to use git-format-patch to create a series of | |
2301 | patches, then reset the state to before the patches: | |
4c63ff45 | 2302 | |
b181d57f BF |
2303 | ------------------------------------------------- |
2304 | $ git format-patch origin | |
2305 | $ git reset --hard origin | |
2306 | ------------------------------------------------- | |
4c63ff45 | 2307 | |
b181d57f BF |
2308 | Then modify, reorder, or eliminate patches as preferred before applying |
2309 | them again with gitlink:git-am[1]. | |
4c63ff45 | 2310 | |
e34caace | 2311 | [[patch-series-tools]] |
4c63ff45 BF |
2312 | Other tools |
2313 | ----------- | |
2314 | ||
b181d57f | 2315 | There are numerous other tools, such as stgit, which exist for the |
79c96c57 | 2316 | purpose of maintaining a patch series. These are outside of the scope of |
b181d57f | 2317 | this manual. |
4c63ff45 | 2318 | |
e34caace | 2319 | [[problems-with-rewriting-history]] |
4c63ff45 BF |
2320 | Problems with rewriting history |
2321 | ------------------------------- | |
2322 | ||
b181d57f BF |
2323 | The primary problem with rewriting the history of a branch has to do |
2324 | with merging. Suppose somebody fetches your branch and merges it into | |
2325 | their branch, with a result something like this: | |
2326 | ||
1dc71a91 | 2327 | ................................................ |
b181d57f BF |
2328 | o--o--O--o--o--o <-- origin |
2329 | \ \ | |
2330 | t--t--t--m <-- their branch: | |
1dc71a91 | 2331 | ................................................ |
b181d57f BF |
2332 | |
2333 | Then suppose you modify the last three commits: | |
2334 | ||
1dc71a91 | 2335 | ................................................ |
b181d57f BF |
2336 | o--o--o <-- new head of origin |
2337 | / | |
2338 | o--o--O--o--o--o <-- old head of origin | |
1dc71a91 | 2339 | ................................................ |
b181d57f BF |
2340 | |
2341 | If we examined all this history together in one repository, it will | |
2342 | look like: | |
2343 | ||
1dc71a91 | 2344 | ................................................ |
b181d57f BF |
2345 | o--o--o <-- new head of origin |
2346 | / | |
2347 | o--o--O--o--o--o <-- old head of origin | |
2348 | \ \ | |
2349 | t--t--t--m <-- their branch: | |
1dc71a91 | 2350 | ................................................ |
b181d57f BF |
2351 | |
2352 | Git has no way of knowing that the new head is an updated version of | |
2353 | the old head; it treats this situation exactly the same as it would if | |
2354 | two developers had independently done the work on the old and new heads | |
2355 | in parallel. At this point, if someone attempts to merge the new head | |
2356 | in to their branch, git will attempt to merge together the two (old and | |
2357 | new) lines of development, instead of trying to replace the old by the | |
2358 | new. The results are likely to be unexpected. | |
2359 | ||
2360 | You may still choose to publish branches whose history is rewritten, | |
2361 | and it may be useful for others to be able to fetch those branches in | |
2362 | order to examine or test them, but they should not attempt to pull such | |
2363 | branches into their own work. | |
2364 | ||
2365 | For true distributed development that supports proper merging, | |
2366 | published branches should never be rewritten. | |
2367 | ||
e34caace | 2368 | [[advanced-branch-management]] |
b181d57f BF |
2369 | Advanced branch management |
2370 | ========================== | |
4c63ff45 | 2371 | |
e34caace | 2372 | [[fetching-individual-branches]] |
b181d57f BF |
2373 | Fetching individual branches |
2374 | ---------------------------- | |
2375 | ||
2376 | Instead of using gitlink:git-remote[1], you can also choose just | |
2377 | to update one branch at a time, and to store it locally under an | |
2378 | arbitrary name: | |
2379 | ||
2380 | ------------------------------------------------- | |
2381 | $ git fetch origin todo:my-todo-work | |
2382 | ------------------------------------------------- | |
2383 | ||
2384 | The first argument, "origin", just tells git to fetch from the | |
2385 | repository you originally cloned from. The second argument tells git | |
2386 | to fetch the branch named "todo" from the remote repository, and to | |
2387 | store it locally under the name refs/heads/my-todo-work. | |
2388 | ||
2389 | You can also fetch branches from other repositories; so | |
2390 | ||
2391 | ------------------------------------------------- | |
2392 | $ git fetch git://example.com/proj.git master:example-master | |
2393 | ------------------------------------------------- | |
2394 | ||
2395 | will create a new branch named "example-master" and store in it the | |
2396 | branch named "master" from the repository at the given URL. If you | |
2397 | already have a branch named example-master, it will attempt to | |
59723040 BF |
2398 | <<fast-forwards,fast-forward>> to the commit given by example.com's |
2399 | master branch. In more detail: | |
b181d57f | 2400 | |
59723040 BF |
2401 | [[fetch-fast-forwards]] |
2402 | git fetch and fast-forwards | |
2403 | --------------------------- | |
b181d57f BF |
2404 | |
2405 | In the previous example, when updating an existing branch, "git | |
2406 | fetch" checks to make sure that the most recent commit on the remote | |
2407 | branch is a descendant of the most recent commit on your copy of the | |
2408 | branch before updating your copy of the branch to point at the new | |
59723040 | 2409 | commit. Git calls this process a <<fast-forwards,fast forward>>. |
b181d57f BF |
2410 | |
2411 | A fast forward looks something like this: | |
2412 | ||
1dc71a91 | 2413 | ................................................ |
b181d57f BF |
2414 | o--o--o--o <-- old head of the branch |
2415 | \ | |
2416 | o--o--o <-- new head of the branch | |
1dc71a91 | 2417 | ................................................ |
b181d57f BF |
2418 | |
2419 | ||
2420 | In some cases it is possible that the new head will *not* actually be | |
2421 | a descendant of the old head. For example, the developer may have | |
2422 | realized she made a serious mistake, and decided to backtrack, | |
2423 | resulting in a situation like: | |
2424 | ||
1dc71a91 | 2425 | ................................................ |
b181d57f BF |
2426 | o--o--o--o--a--b <-- old head of the branch |
2427 | \ | |
2428 | o--o--o <-- new head of the branch | |
1dc71a91 | 2429 | ................................................ |
b181d57f BF |
2430 | |
2431 | In this case, "git fetch" will fail, and print out a warning. | |
2432 | ||
2433 | In that case, you can still force git to update to the new head, as | |
2434 | described in the following section. However, note that in the | |
2435 | situation above this may mean losing the commits labeled "a" and "b", | |
2436 | unless you've already created a reference of your own pointing to | |
2437 | them. | |
2438 | ||
e34caace | 2439 | [[forcing-fetch]] |
b181d57f BF |
2440 | Forcing git fetch to do non-fast-forward updates |
2441 | ------------------------------------------------ | |
2442 | ||
2443 | If git fetch fails because the new head of a branch is not a | |
2444 | descendant of the old head, you may force the update with: | |
2445 | ||
2446 | ------------------------------------------------- | |
2447 | $ git fetch git://example.com/proj.git +master:refs/remotes/example/master | |
2448 | ------------------------------------------------- | |
2449 | ||
c64415e2 BF |
2450 | Note the addition of the "+" sign. Alternatively, you can use the "-f" |
2451 | flag to force updates of all the fetched branches, as in: | |
2452 | ||
2453 | ------------------------------------------------- | |
2454 | $ git fetch -f origin | |
2455 | ------------------------------------------------- | |
2456 | ||
2457 | Be aware that commits that the old version of example/master pointed at | |
2458 | may be lost, as we saw in the previous section. | |
b181d57f | 2459 | |
e34caace | 2460 | [[remote-branch-configuration]] |
b181d57f BF |
2461 | Configuring remote branches |
2462 | --------------------------- | |
2463 | ||
2464 | We saw above that "origin" is just a shortcut to refer to the | |
79c96c57 | 2465 | repository that you originally cloned from. This information is |
b181d57f | 2466 | stored in git configuration variables, which you can see using |
9d13bda3 | 2467 | gitlink:git-config[1]: |
b181d57f BF |
2468 | |
2469 | ------------------------------------------------- | |
9d13bda3 | 2470 | $ git config -l |
b181d57f BF |
2471 | core.repositoryformatversion=0 |
2472 | core.filemode=true | |
2473 | core.logallrefupdates=true | |
2474 | remote.origin.url=git://git.kernel.org/pub/scm/git/git.git | |
2475 | remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* | |
2476 | branch.master.remote=origin | |
2477 | branch.master.merge=refs/heads/master | |
2478 | ------------------------------------------------- | |
2479 | ||
2480 | If there are other repositories that you also use frequently, you can | |
2481 | create similar configuration options to save typing; for example, | |
2482 | after | |
2483 | ||
2484 | ------------------------------------------------- | |
9d13bda3 | 2485 | $ git config remote.example.url git://example.com/proj.git |
b181d57f BF |
2486 | ------------------------------------------------- |
2487 | ||
2488 | then the following two commands will do the same thing: | |
2489 | ||
2490 | ------------------------------------------------- | |
2491 | $ git fetch git://example.com/proj.git master:refs/remotes/example/master | |
2492 | $ git fetch example master:refs/remotes/example/master | |
2493 | ------------------------------------------------- | |
2494 | ||
2495 | Even better, if you add one more option: | |
2496 | ||
2497 | ------------------------------------------------- | |
9d13bda3 | 2498 | $ git config remote.example.fetch master:refs/remotes/example/master |
b181d57f BF |
2499 | ------------------------------------------------- |
2500 | ||
2501 | then the following commands will all do the same thing: | |
2502 | ||
2503 | ------------------------------------------------- | |
52c80037 BF |
2504 | $ git fetch git://example.com/proj.git master:refs/remotes/example/master |
2505 | $ git fetch example master:refs/remotes/example/master | |
b181d57f BF |
2506 | $ git fetch example |
2507 | ------------------------------------------------- | |
2508 | ||
2509 | You can also add a "+" to force the update each time: | |
2510 | ||
2511 | ------------------------------------------------- | |
9d13bda3 | 2512 | $ git config remote.example.fetch +master:ref/remotes/example/master |
b181d57f BF |
2513 | ------------------------------------------------- |
2514 | ||
2515 | Don't do this unless you're sure you won't mind "git fetch" possibly | |
2516 | throwing away commits on mybranch. | |
2517 | ||
2518 | Also note that all of the above configuration can be performed by | |
2519 | directly editing the file .git/config instead of using | |
9d13bda3 | 2520 | gitlink:git-config[1]. |
b181d57f | 2521 | |
9d13bda3 | 2522 | See gitlink:git-config[1] for more details on the configuration |
b181d57f | 2523 | options mentioned above. |
d19fbc3c | 2524 | |
d19fbc3c | 2525 | |
35121930 | 2526 | [[git-internals]] |
d19fbc3c BF |
2527 | Git internals |
2528 | ============= | |
2529 | ||
a536b08b BF |
2530 | Git depends on two fundamental abstractions: the "object database", and |
2531 | the "current directory cache" aka "index". | |
b181d57f | 2532 | |
e34caace | 2533 | [[the-object-database]] |
b181d57f BF |
2534 | The Object Database |
2535 | ------------------- | |
2536 | ||
2537 | The object database is literally just a content-addressable collection | |
2538 | of objects. All objects are named by their content, which is | |
2539 | approximated by the SHA1 hash of the object itself. Objects may refer | |
2540 | to other objects (by referencing their SHA1 hash), and so you can | |
2541 | build up a hierarchy of objects. | |
2542 | ||
c64415e2 | 2543 | All objects have a statically determined "type" which is |
b181d57f BF |
2544 | determined at object creation time, and which identifies the format of |
2545 | the object (i.e. how it is used, and how it can refer to other | |
2546 | objects). There are currently four different object types: "blob", | |
a536b08b | 2547 | "tree", "commit", and "tag". |
b181d57f | 2548 | |
a536b08b BF |
2549 | A <<def_blob_object,"blob" object>> cannot refer to any other object, |
2550 | and is, as the name implies, a pure storage object containing some | |
2551 | user data. It is used to actually store the file data, i.e. a blob | |
2552 | object is associated with some particular version of some file. | |
b181d57f | 2553 | |
a536b08b BF |
2554 | A <<def_tree_object,"tree" object>> is an object that ties one or more |
2555 | "blob" objects into a directory structure. In addition, a tree object | |
2556 | can refer to other tree objects, thus creating a directory hierarchy. | |
b181d57f | 2557 | |
a536b08b BF |
2558 | A <<def_commit_object,"commit" object>> ties such directory hierarchies |
2559 | together into a <<def_DAG,directed acyclic graph>> of revisions - each | |
2560 | "commit" is associated with exactly one tree (the directory hierarchy at | |
2561 | the time of the commit). In addition, a "commit" refers to one or more | |
2562 | "parent" commit objects that describe the history of how we arrived at | |
2563 | that directory hierarchy. | |
b181d57f BF |
2564 | |
2565 | As a special case, a commit object with no parents is called the "root" | |
c64415e2 | 2566 | commit, and is the point of an initial project commit. Each project |
b181d57f BF |
2567 | must have at least one root, and while you can tie several different |
2568 | root objects together into one project by creating a commit object which | |
2569 | has two or more separate roots as its ultimate parents, that's probably | |
2570 | just going to confuse people. So aim for the notion of "one root object | |
2571 | per project", even if git itself does not enforce that. | |
2572 | ||
a536b08b BF |
2573 | A <<def_tag_object,"tag" object>> symbolically identifies and can be |
2574 | used to sign other objects. It contains the identifier and type of | |
2575 | another object, a symbolic name (of course!) and, optionally, a | |
2576 | signature. | |
b181d57f BF |
2577 | |
2578 | Regardless of object type, all objects share the following | |
2579 | characteristics: they are all deflated with zlib, and have a header | |
2580 | that not only specifies their type, but also provides size information | |
2581 | about the data in the object. It's worth noting that the SHA1 hash | |
2582 | that is used to name the object is the hash of the original data | |
2583 | plus this header, so `sha1sum` 'file' does not match the object name | |
2584 | for 'file'. | |
2585 | (Historical note: in the dawn of the age of git the hash | |
2586 | was the sha1 of the 'compressed' object.) | |
2587 | ||
2588 | As a result, the general consistency of an object can always be tested | |
2589 | independently of the contents or the type of the object: all objects can | |
2590 | be validated by verifying that (a) their hashes match the content of the | |
2591 | file and (b) the object successfully inflates to a stream of bytes that | |
2592 | forms a sequence of <ascii type without space> + <space> + <ascii decimal | |
2593 | size> + <byte\0> + <binary object data>. | |
2594 | ||
2595 | The structured objects can further have their structure and | |
2596 | connectivity to other objects verified. This is generally done with | |
04e50e94 | 2597 | the `git-fsck` program, which generates a full dependency graph |
b181d57f BF |
2598 | of all objects, and verifies their internal consistency (in addition |
2599 | to just verifying their superficial consistency through the hash). | |
2600 | ||
2601 | The object types in some more detail: | |
2602 | ||
e34caace | 2603 | [[blob-object]] |
b181d57f BF |
2604 | Blob Object |
2605 | ----------- | |
2606 | ||
2607 | A "blob" object is nothing but a binary blob of data, and doesn't | |
2608 | refer to anything else. There is no signature or any other | |
2609 | verification of the data, so while the object is consistent (it 'is' | |
2610 | indexed by its sha1 hash, so the data itself is certainly correct), it | |
2611 | has absolutely no other attributes. No name associations, no | |
2612 | permissions. It is purely a blob of data (i.e. normally "file | |
2613 | contents"). | |
2614 | ||
2615 | In particular, since the blob is entirely defined by its data, if two | |
2616 | files in a directory tree (or in multiple different versions of the | |
2617 | repository) have the same contents, they will share the same blob | |
2618 | object. The object is totally independent of its location in the | |
2619 | directory tree, and renaming a file does not change the object that | |
2620 | file is associated with in any way. | |
2621 | ||
2622 | A blob is typically created when gitlink:git-update-index[1] | |
2623 | is run, and its data can be accessed by gitlink:git-cat-file[1]. | |
2624 | ||
e34caace | 2625 | [[tree-object]] |
b181d57f BF |
2626 | Tree Object |
2627 | ----------- | |
2628 | ||
2629 | The next hierarchical object type is the "tree" object. A tree object | |
2630 | is a list of mode/name/blob data, sorted by name. Alternatively, the | |
2631 | mode data may specify a directory mode, in which case instead of | |
2632 | naming a blob, that name is associated with another TREE object. | |
2633 | ||
2634 | Like the "blob" object, a tree object is uniquely determined by the | |
2635 | set contents, and so two separate but identical trees will always | |
2636 | share the exact same object. This is true at all levels, i.e. it's | |
2637 | true for a "leaf" tree (which does not refer to any other trees, only | |
2638 | blobs) as well as for a whole subdirectory. | |
2639 | ||
2640 | For that reason a "tree" object is just a pure data abstraction: it | |
2641 | has no history, no signatures, no verification of validity, except | |
2642 | that since the contents are again protected by the hash itself, we can | |
2643 | trust that the tree is immutable and its contents never change. | |
2644 | ||
2645 | So you can trust the contents of a tree to be valid, the same way you | |
2646 | can trust the contents of a blob, but you don't know where those | |
2647 | contents 'came' from. | |
2648 | ||
2649 | Side note on trees: since a "tree" object is a sorted list of | |
2650 | "filename+content", you can create a diff between two trees without | |
2651 | actually having to unpack two trees. Just ignore all common parts, | |
2652 | and your diff will look right. In other words, you can effectively | |
2653 | (and efficiently) tell the difference between any two random trees by | |
2654 | O(n) where "n" is the size of the difference, rather than the size of | |
2655 | the tree. | |
2656 | ||
2657 | Side note 2 on trees: since the name of a "blob" depends entirely and | |
2658 | exclusively on its contents (i.e. there are no names or permissions | |
2659 | involved), you can see trivial renames or permission changes by | |
2660 | noticing that the blob stayed the same. However, renames with data | |
2661 | changes need a smarter "diff" implementation. | |
2662 | ||
2663 | A tree is created with gitlink:git-write-tree[1] and | |
2664 | its data can be accessed by gitlink:git-ls-tree[1]. | |
2665 | Two trees can be compared with gitlink:git-diff-tree[1]. | |
2666 | ||
e34caace | 2667 | [[commit-object]] |
b181d57f BF |
2668 | Commit Object |
2669 | ------------- | |
2670 | ||
2671 | The "commit" object is an object that introduces the notion of | |
2672 | history into the picture. In contrast to the other objects, it | |
2673 | doesn't just describe the physical state of a tree, it describes how | |
2674 | we got there, and why. | |
2675 | ||
2676 | A "commit" is defined by the tree-object that it results in, the | |
2677 | parent commits (zero, one or more) that led up to that point, and a | |
2678 | comment on what happened. Again, a commit is not trusted per se: | |
2679 | the contents are well-defined and "safe" due to the cryptographically | |
2680 | strong signatures at all levels, but there is no reason to believe | |
2681 | that the tree is "good" or that the merge information makes sense. | |
2682 | The parents do not have to actually have any relationship with the | |
2683 | result, for example. | |
2684 | ||
c64415e2 | 2685 | Note on commits: unlike some SCM's, commits do not contain |
b181d57f BF |
2686 | rename information or file mode change information. All of that is |
2687 | implicit in the trees involved (the result tree, and the result trees | |
2688 | of the parents), and describing that makes no sense in this idiotic | |
2689 | file manager. | |
2690 | ||
2691 | A commit is created with gitlink:git-commit-tree[1] and | |
2692 | its data can be accessed by gitlink:git-cat-file[1]. | |
2693 | ||
e34caace | 2694 | [[trust]] |
b181d57f BF |
2695 | Trust |
2696 | ----- | |
2697 | ||
2698 | An aside on the notion of "trust". Trust is really outside the scope | |
2699 | of "git", but it's worth noting a few things. First off, since | |
2700 | everything is hashed with SHA1, you 'can' trust that an object is | |
2701 | intact and has not been messed with by external sources. So the name | |
2702 | of an object uniquely identifies a known state - just not a state that | |
2703 | you may want to trust. | |
2704 | ||
2705 | Furthermore, since the SHA1 signature of a commit refers to the | |
2706 | SHA1 signatures of the tree it is associated with and the signatures | |
2707 | of the parent, a single named commit specifies uniquely a whole set | |
2708 | of history, with full contents. You can't later fake any step of the | |
2709 | way once you have the name of a commit. | |
2710 | ||
2711 | So to introduce some real trust in the system, the only thing you need | |
2712 | to do is to digitally sign just 'one' special note, which includes the | |
2713 | name of a top-level commit. Your digital signature shows others | |
2714 | that you trust that commit, and the immutability of the history of | |
2715 | commits tells others that they can trust the whole history. | |
2716 | ||
2717 | In other words, you can easily validate a whole archive by just | |
2718 | sending out a single email that tells the people the name (SHA1 hash) | |
2719 | of the top commit, and digitally sign that email using something | |
2720 | like GPG/PGP. | |
2721 | ||
2722 | To assist in this, git also provides the tag object... | |
2723 | ||
e34caace | 2724 | [[tag-object]] |
b181d57f BF |
2725 | Tag Object |
2726 | ---------- | |
2727 | ||
2728 | Git provides the "tag" object to simplify creating, managing and | |
2729 | exchanging symbolic and signed tokens. The "tag" object at its | |
2730 | simplest simply symbolically identifies another object by containing | |
2731 | the sha1, type and symbolic name. | |
2732 | ||
2733 | However it can optionally contain additional signature information | |
2734 | (which git doesn't care about as long as there's less than 8k of | |
2735 | it). This can then be verified externally to git. | |
2736 | ||
2737 | Note that despite the tag features, "git" itself only handles content | |
2738 | integrity; the trust framework (and signature provision and | |
2739 | verification) has to come from outside. | |
2740 | ||
2741 | A tag is created with gitlink:git-mktag[1], | |
2742 | its data can be accessed by gitlink:git-cat-file[1], | |
2743 | and the signature can be verified by | |
2744 | gitlink:git-verify-tag[1]. | |
2745 | ||
2746 | ||
e34caace | 2747 | [[the-index]] |
b181d57f BF |
2748 | The "index" aka "Current Directory Cache" |
2749 | ----------------------------------------- | |
2750 | ||
2751 | The index is a simple binary file, which contains an efficient | |
c64415e2 | 2752 | representation of the contents of a virtual directory. It |
b181d57f BF |
2753 | does so by a simple array that associates a set of names, dates, |
2754 | permissions and content (aka "blob") objects together. The cache is | |
2755 | always kept ordered by name, and names are unique (with a few very | |
2756 | specific rules) at any point in time, but the cache has no long-term | |
2757 | meaning, and can be partially updated at any time. | |
2758 | ||
2759 | In particular, the index certainly does not need to be consistent with | |
2760 | the current directory contents (in fact, most operations will depend on | |
2761 | different ways to make the index 'not' be consistent with the directory | |
2762 | hierarchy), but it has three very important attributes: | |
2763 | ||
2764 | '(a) it can re-generate the full state it caches (not just the | |
2765 | directory structure: it contains pointers to the "blob" objects so | |
2766 | that it can regenerate the data too)' | |
2767 | ||
2768 | As a special case, there is a clear and unambiguous one-way mapping | |
2769 | from a current directory cache to a "tree object", which can be | |
2770 | efficiently created from just the current directory cache without | |
2771 | actually looking at any other data. So a directory cache at any one | |
2772 | time uniquely specifies one and only one "tree" object (but has | |
2773 | additional data to make it easy to match up that tree object with what | |
2774 | has happened in the directory) | |
2775 | ||
2776 | '(b) it has efficient methods for finding inconsistencies between that | |
2777 | cached state ("tree object waiting to be instantiated") and the | |
2778 | current state.' | |
2779 | ||
2780 | '(c) it can additionally efficiently represent information about merge | |
2781 | conflicts between different tree objects, allowing each pathname to be | |
2782 | associated with sufficient information about the trees involved that | |
2783 | you can create a three-way merge between them.' | |
2784 | ||
79c96c57 | 2785 | Those are the ONLY three things that the directory cache does. It's a |
b181d57f BF |
2786 | cache, and the normal operation is to re-generate it completely from a |
2787 | known tree object, or update/compare it with a live tree that is being | |
2788 | developed. If you blow the directory cache away entirely, you generally | |
2789 | haven't lost any information as long as you have the name of the tree | |
2790 | that it described. | |
2791 | ||
2792 | At the same time, the index is at the same time also the | |
2793 | staging area for creating new trees, and creating a new tree always | |
2794 | involves a controlled modification of the index file. In particular, | |
2795 | the index file can have the representation of an intermediate tree that | |
2796 | has not yet been instantiated. So the index can be thought of as a | |
2797 | write-back cache, which can contain dirty information that has not yet | |
2798 | been written back to the backing store. | |
2799 | ||
2800 | ||
2801 | ||
e34caace | 2802 | [[the-workflow]] |
b181d57f BF |
2803 | The Workflow |
2804 | ------------ | |
2805 | ||
2806 | Generally, all "git" operations work on the index file. Some operations | |
2807 | work *purely* on the index file (showing the current state of the | |
2808 | index), but most operations move data to and from the index file. Either | |
2809 | from the database or from the working directory. Thus there are four | |
2810 | main combinations: | |
2811 | ||
e34caace | 2812 | [[working-directory-to-index]] |
b181d57f BF |
2813 | working directory -> index |
2814 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
2815 | ||
2816 | You update the index with information from the working directory with | |
2817 | the gitlink:git-update-index[1] command. You | |
2818 | generally update the index information by just specifying the filename | |
2819 | you want to update, like so: | |
2820 | ||
2821 | ------------------------------------------------- | |
2822 | $ git-update-index filename | |
2823 | ------------------------------------------------- | |
2824 | ||
2825 | but to avoid common mistakes with filename globbing etc, the command | |
2826 | will not normally add totally new entries or remove old entries, | |
2827 | i.e. it will normally just update existing cache entries. | |
2828 | ||
2829 | To tell git that yes, you really do realize that certain files no | |
2830 | longer exist, or that new files should be added, you | |
2831 | should use the `--remove` and `--add` flags respectively. | |
2832 | ||
2833 | NOTE! A `--remove` flag does 'not' mean that subsequent filenames will | |
2834 | necessarily be removed: if the files still exist in your directory | |
2835 | structure, the index will be updated with their new status, not | |
2836 | removed. The only thing `--remove` means is that update-cache will be | |
2837 | considering a removed file to be a valid thing, and if the file really | |
2838 | does not exist any more, it will update the index accordingly. | |
2839 | ||
2840 | As a special case, you can also do `git-update-index --refresh`, which | |
2841 | will refresh the "stat" information of each index to match the current | |
2842 | stat information. It will 'not' update the object status itself, and | |
2843 | it will only update the fields that are used to quickly test whether | |
2844 | an object still matches its old backing store object. | |
2845 | ||
e34caace | 2846 | [[index-to-object-database]] |
b181d57f BF |
2847 | index -> object database |
2848 | ~~~~~~~~~~~~~~~~~~~~~~~~ | |
2849 | ||
2850 | You write your current index file to a "tree" object with the program | |
2851 | ||
2852 | ------------------------------------------------- | |
2853 | $ git-write-tree | |
2854 | ------------------------------------------------- | |
2855 | ||
2856 | that doesn't come with any options - it will just write out the | |
2857 | current index into the set of tree objects that describe that state, | |
2858 | and it will return the name of the resulting top-level tree. You can | |
2859 | use that tree to re-generate the index at any time by going in the | |
2860 | other direction: | |
2861 | ||
e34caace | 2862 | [[object-database-to-index]] |
b181d57f BF |
2863 | object database -> index |
2864 | ~~~~~~~~~~~~~~~~~~~~~~~~ | |
2865 | ||
2866 | You read a "tree" file from the object database, and use that to | |
2867 | populate (and overwrite - don't do this if your index contains any | |
2868 | unsaved state that you might want to restore later!) your current | |
2869 | index. Normal operation is just | |
2870 | ||
2871 | ------------------------------------------------- | |
2872 | $ git-read-tree <sha1 of tree> | |
2873 | ------------------------------------------------- | |
2874 | ||
2875 | and your index file will now be equivalent to the tree that you saved | |
2876 | earlier. However, that is only your 'index' file: your working | |
2877 | directory contents have not been modified. | |
2878 | ||
e34caace | 2879 | [[index-to-working-directory]] |
b181d57f BF |
2880 | index -> working directory |
2881 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
2882 | ||
2883 | You update your working directory from the index by "checking out" | |
2884 | files. This is not a very common operation, since normally you'd just | |
2885 | keep your files updated, and rather than write to your working | |
2886 | directory, you'd tell the index files about the changes in your | |
2887 | working directory (i.e. `git-update-index`). | |
2888 | ||
2889 | However, if you decide to jump to a new version, or check out somebody | |
2890 | else's version, or just restore a previous tree, you'd populate your | |
2891 | index file with read-tree, and then you need to check out the result | |
2892 | with | |
2893 | ||
2894 | ------------------------------------------------- | |
2895 | $ git-checkout-index filename | |
2896 | ------------------------------------------------- | |
2897 | ||
2898 | or, if you want to check out all of the index, use `-a`. | |
2899 | ||
2900 | NOTE! git-checkout-index normally refuses to overwrite old files, so | |
2901 | if you have an old version of the tree already checked out, you will | |
2902 | need to use the "-f" flag ('before' the "-a" flag or the filename) to | |
2903 | 'force' the checkout. | |
2904 | ||
2905 | ||
2906 | Finally, there are a few odds and ends which are not purely moving | |
2907 | from one representation to the other: | |
2908 | ||
e34caace | 2909 | [[tying-it-all-together]] |
b181d57f BF |
2910 | Tying it all together |
2911 | ~~~~~~~~~~~~~~~~~~~~~ | |
2912 | ||
2913 | To commit a tree you have instantiated with "git-write-tree", you'd | |
2914 | create a "commit" object that refers to that tree and the history | |
2915 | behind it - most notably the "parent" commits that preceded it in | |
2916 | history. | |
2917 | ||
2918 | Normally a "commit" has one parent: the previous state of the tree | |
2919 | before a certain change was made. However, sometimes it can have two | |
2920 | or more parent commits, in which case we call it a "merge", due to the | |
2921 | fact that such a commit brings together ("merges") two or more | |
2922 | previous states represented by other commits. | |
2923 | ||
2924 | In other words, while a "tree" represents a particular directory state | |
2925 | of a working directory, a "commit" represents that state in "time", | |
2926 | and explains how we got there. | |
2927 | ||
2928 | You create a commit object by giving it the tree that describes the | |
2929 | state at the time of the commit, and a list of parents: | |
2930 | ||
2931 | ------------------------------------------------- | |
2932 | $ git-commit-tree <tree> -p <parent> [-p <parent2> ..] | |
2933 | ------------------------------------------------- | |
2934 | ||
2935 | and then giving the reason for the commit on stdin (either through | |
2936 | redirection from a pipe or file, or by just typing it at the tty). | |
2937 | ||
2938 | git-commit-tree will return the name of the object that represents | |
2939 | that commit, and you should save it away for later use. Normally, | |
2940 | you'd commit a new `HEAD` state, and while git doesn't care where you | |
2941 | save the note about that state, in practice we tend to just write the | |
2942 | result to the file pointed at by `.git/HEAD`, so that we can always see | |
2943 | what the last committed state was. | |
2944 | ||
2945 | Here is an ASCII art by Jon Loeliger that illustrates how | |
2946 | various pieces fit together. | |
2947 | ||
2948 | ------------ | |
2949 | ||
2950 | commit-tree | |
2951 | commit obj | |
2952 | +----+ | |
2953 | | | | |
2954 | | | | |
2955 | V V | |
2956 | +-----------+ | |
2957 | | Object DB | | |
2958 | | Backing | | |
2959 | | Store | | |
2960 | +-----------+ | |
2961 | ^ | |
2962 | write-tree | | | |
2963 | tree obj | | | |
2964 | | | read-tree | |
2965 | | | tree obj | |
2966 | V | |
2967 | +-----------+ | |
2968 | | Index | | |
2969 | | "cache" | | |
2970 | +-----------+ | |
2971 | update-index ^ | |
2972 | blob obj | | | |
2973 | | | | |
2974 | checkout-index -u | | checkout-index | |
2975 | stat | | blob obj | |
2976 | V | |
2977 | +-----------+ | |
2978 | | Working | | |
2979 | | Directory | | |
2980 | +-----------+ | |
2981 | ||
2982 | ------------ | |
2983 | ||
2984 | ||
e34caace | 2985 | [[examining-the-data]] |
b181d57f BF |
2986 | Examining the data |
2987 | ------------------ | |
2988 | ||
2989 | You can examine the data represented in the object database and the | |
2990 | index with various helper tools. For every object, you can use | |
2991 | gitlink:git-cat-file[1] to examine details about the | |
2992 | object: | |
2993 | ||
2994 | ------------------------------------------------- | |
2995 | $ git-cat-file -t <objectname> | |
2996 | ------------------------------------------------- | |
2997 | ||
2998 | shows the type of the object, and once you have the type (which is | |
2999 | usually implicit in where you find the object), you can use | |
3000 | ||
3001 | ------------------------------------------------- | |
3002 | $ git-cat-file blob|tree|commit|tag <objectname> | |
3003 | ------------------------------------------------- | |
3004 | ||
3005 | to show its contents. NOTE! Trees have binary content, and as a result | |
3006 | there is a special helper for showing that content, called | |
3007 | `git-ls-tree`, which turns the binary content into a more easily | |
3008 | readable form. | |
3009 | ||
3010 | It's especially instructive to look at "commit" objects, since those | |
3011 | tend to be small and fairly self-explanatory. In particular, if you | |
3012 | follow the convention of having the top commit name in `.git/HEAD`, | |
3013 | you can do | |
3014 | ||
3015 | ------------------------------------------------- | |
3016 | $ git-cat-file commit HEAD | |
3017 | ------------------------------------------------- | |
3018 | ||
3019 | to see what the top commit was. | |
3020 | ||
e34caace | 3021 | [[merging-multiple-trees]] |
b181d57f | 3022 | Merging multiple trees |
d19fbc3c BF |
3023 | ---------------------- |
3024 | ||
b181d57f BF |
3025 | Git helps you do a three-way merge, which you can expand to n-way by |
3026 | repeating the merge procedure arbitrary times until you finally | |
3027 | "commit" the state. The normal situation is that you'd only do one | |
3028 | three-way merge (two parents), and commit it, but if you like to, you | |
3029 | can do multiple parents in one go. | |
3030 | ||
3031 | To do a three-way merge, you need the two sets of "commit" objects | |
3032 | that you want to merge, use those to find the closest common parent (a | |
3033 | third "commit" object), and then use those commit objects to find the | |
3034 | state of the directory ("tree" object) at these points. | |
3035 | ||
3036 | To get the "base" for the merge, you first look up the common parent | |
3037 | of two commits with | |
3038 | ||
3039 | ------------------------------------------------- | |
3040 | $ git-merge-base <commit1> <commit2> | |
3041 | ------------------------------------------------- | |
3042 | ||
3043 | which will return you the commit they are both based on. You should | |
3044 | now look up the "tree" objects of those commits, which you can easily | |
3045 | do with (for example) | |
3046 | ||
3047 | ------------------------------------------------- | |
3048 | $ git-cat-file commit <commitname> | head -1 | |
3049 | ------------------------------------------------- | |
3050 | ||
3051 | since the tree object information is always the first line in a commit | |
3052 | object. | |
3053 | ||
1191ee18 | 3054 | Once you know the three trees you are going to merge (the one "original" |
c64415e2 | 3055 | tree, aka the common tree, and the two "result" trees, aka the branches |
1191ee18 BF |
3056 | you want to merge), you do a "merge" read into the index. This will |
3057 | complain if it has to throw away your old index contents, so you should | |
b181d57f | 3058 | make sure that you've committed those - in fact you would normally |
1191ee18 BF |
3059 | always do a merge against your last commit (which should thus match what |
3060 | you have in your current index anyway). | |
b181d57f BF |
3061 | |
3062 | To do the merge, do | |
3063 | ||
3064 | ------------------------------------------------- | |
3065 | $ git-read-tree -m -u <origtree> <yourtree> <targettree> | |
3066 | ------------------------------------------------- | |
3067 | ||
3068 | which will do all trivial merge operations for you directly in the | |
3069 | index file, and you can just write the result out with | |
3070 | `git-write-tree`. | |
3071 | ||
3072 | ||
e34caace | 3073 | [[merging-multiple-trees-2]] |
b181d57f BF |
3074 | Merging multiple trees, continued |
3075 | --------------------------------- | |
3076 | ||
3077 | Sadly, many merges aren't trivial. If there are files that have | |
3078 | been added.moved or removed, or if both branches have modified the | |
3079 | same file, you will be left with an index tree that contains "merge | |
3080 | entries" in it. Such an index tree can 'NOT' be written out to a tree | |
3081 | object, and you will have to resolve any such merge clashes using | |
3082 | other tools before you can write out the result. | |
3083 | ||
3084 | You can examine such index state with `git-ls-files --unmerged` | |
3085 | command. An example: | |
3086 | ||
3087 | ------------------------------------------------ | |
3088 | $ git-read-tree -m $orig HEAD $target | |
3089 | $ git-ls-files --unmerged | |
3090 | 100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello.c | |
3091 | 100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello.c | |
3092 | 100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello.c | |
3093 | ------------------------------------------------ | |
3094 | ||
3095 | Each line of the `git-ls-files --unmerged` output begins with | |
3096 | the blob mode bits, blob SHA1, 'stage number', and the | |
3097 | filename. The 'stage number' is git's way to say which tree it | |
3098 | came from: stage 1 corresponds to `$orig` tree, stage 2 `HEAD` | |
3099 | tree, and stage3 `$target` tree. | |
3100 | ||
3101 | Earlier we said that trivial merges are done inside | |
3102 | `git-read-tree -m`. For example, if the file did not change | |
3103 | from `$orig` to `HEAD` nor `$target`, or if the file changed | |
3104 | from `$orig` to `HEAD` and `$orig` to `$target` the same way, | |
3105 | obviously the final outcome is what is in `HEAD`. What the | |
3106 | above example shows is that file `hello.c` was changed from | |
3107 | `$orig` to `HEAD` and `$orig` to `$target` in a different way. | |
3108 | You could resolve this by running your favorite 3-way merge | |
c64415e2 BF |
3109 | program, e.g. `diff3`, `merge`, or git's own merge-file, on |
3110 | the blob objects from these three stages yourself, like this: | |
b181d57f BF |
3111 | |
3112 | ------------------------------------------------ | |
3113 | $ git-cat-file blob 263414f... >hello.c~1 | |
3114 | $ git-cat-file blob 06fa6a2... >hello.c~2 | |
3115 | $ git-cat-file blob cc44c73... >hello.c~3 | |
c64415e2 | 3116 | $ git merge-file hello.c~2 hello.c~1 hello.c~3 |
b181d57f BF |
3117 | ------------------------------------------------ |
3118 | ||
3119 | This would leave the merge result in `hello.c~2` file, along | |
3120 | with conflict markers if there are conflicts. After verifying | |
3121 | the merge result makes sense, you can tell git what the final | |
3122 | merge result for this file is by: | |
3123 | ||
3124 | ------------------------------------------------- | |
3125 | $ mv -f hello.c~2 hello.c | |
3126 | $ git-update-index hello.c | |
3127 | ------------------------------------------------- | |
3128 | ||
3129 | When a path is in unmerged state, running `git-update-index` for | |
3130 | that path tells git to mark the path resolved. | |
3131 | ||
3132 | The above is the description of a git merge at the lowest level, | |
3133 | to help you understand what conceptually happens under the hood. | |
3134 | In practice, nobody, not even git itself, uses three `git-cat-file` | |
3135 | for this. There is `git-merge-index` program that extracts the | |
3136 | stages to temporary files and calls a "merge" script on it: | |
3137 | ||
3138 | ------------------------------------------------- | |
3139 | $ git-merge-index git-merge-one-file hello.c | |
3140 | ------------------------------------------------- | |
3141 | ||
207dfa07 | 3142 | and that is what higher level `git merge -s resolve` is implemented with. |
b181d57f | 3143 | |
e34caace | 3144 | [[pack-files]] |
b181d57f BF |
3145 | How git stores objects efficiently: pack files |
3146 | ---------------------------------------------- | |
3147 | ||
3148 | We've seen how git stores each object in a file named after the | |
3149 | object's SHA1 hash. | |
3150 | ||
3151 | Unfortunately this system becomes inefficient once a project has a | |
3152 | lot of objects. Try this on an old project: | |
3153 | ||
3154 | ------------------------------------------------ | |
3155 | $ git count-objects | |
3156 | 6930 objects, 47620 kilobytes | |
3157 | ------------------------------------------------ | |
3158 | ||
3159 | The first number is the number of objects which are kept in | |
3160 | individual files. The second is the amount of space taken up by | |
3161 | those "loose" objects. | |
3162 | ||
3163 | You can save space and make git faster by moving these loose objects in | |
3164 | to a "pack file", which stores a group of objects in an efficient | |
3165 | compressed format; the details of how pack files are formatted can be | |
3166 | found in link:technical/pack-format.txt[technical/pack-format.txt]. | |
3167 | ||
3168 | To put the loose objects into a pack, just run git repack: | |
3169 | ||
3170 | ------------------------------------------------ | |
3171 | $ git repack | |
3172 | Generating pack... | |
3173 | Done counting 6020 objects. | |
3174 | Deltifying 6020 objects. | |
3175 | 100% (6020/6020) done | |
3176 | Writing 6020 objects. | |
3177 | 100% (6020/6020) done | |
3178 | Total 6020, written 6020 (delta 4070), reused 0 (delta 0) | |
3179 | Pack pack-3e54ad29d5b2e05838c75df582c65257b8d08e1c created. | |
3180 | ------------------------------------------------ | |
3181 | ||
3182 | You can then run | |
3183 | ||
3184 | ------------------------------------------------ | |
3185 | $ git prune | |
3186 | ------------------------------------------------ | |
3187 | ||
3188 | to remove any of the "loose" objects that are now contained in the | |
3189 | pack. This will also remove any unreferenced objects (which may be | |
3190 | created when, for example, you use "git reset" to remove a commit). | |
3191 | You can verify that the loose objects are gone by looking at the | |
3192 | .git/objects directory or by running | |
3193 | ||
3194 | ------------------------------------------------ | |
3195 | $ git count-objects | |
3196 | 0 objects, 0 kilobytes | |
3197 | ------------------------------------------------ | |
3198 | ||
3199 | Although the object files are gone, any commands that refer to those | |
3200 | objects will work exactly as they did before. | |
3201 | ||
3202 | The gitlink:git-gc[1] command performs packing, pruning, and more for | |
3203 | you, so is normally the only high-level command you need. | |
d19fbc3c | 3204 | |
59723040 | 3205 | [[dangling-objects]] |
21dcb3b7 | 3206 | Dangling objects |
61b41790 | 3207 | ---------------- |
21dcb3b7 | 3208 | |
04e50e94 | 3209 | The gitlink:git-fsck[1] command will sometimes complain about dangling |
21dcb3b7 BF |
3210 | objects. They are not a problem. |
3211 | ||
1191ee18 BF |
3212 | The most common cause of dangling objects is that you've rebased a |
3213 | branch, or you have pulled from somebody else who rebased a branch--see | |
3214 | <<cleaning-up-history>>. In that case, the old head of the original | |
59723040 BF |
3215 | branch still exists, as does everything it pointed to. The branch |
3216 | pointer itself just doesn't, since you replaced it with another one. | |
1191ee18 | 3217 | |
59723040 | 3218 | There are also other situations that cause dangling objects. For |
1191ee18 BF |
3219 | example, a "dangling blob" may arise because you did a "git add" of a |
3220 | file, but then, before you actually committed it and made it part of the | |
3221 | bigger picture, you changed something else in that file and committed | |
3222 | that *updated* thing - the old state that you added originally ends up | |
3223 | not being pointed to by any commit or tree, so it's now a dangling blob | |
3224 | object. | |
3225 | ||
3226 | Similarly, when the "recursive" merge strategy runs, and finds that | |
3227 | there are criss-cross merges and thus more than one merge base (which is | |
3228 | fairly unusual, but it does happen), it will generate one temporary | |
3229 | midway tree (or possibly even more, if you had lots of criss-crossing | |
3230 | merges and more than two merge bases) as a temporary internal merge | |
3231 | base, and again, those are real objects, but the end result will not end | |
3232 | up pointing to them, so they end up "dangling" in your repository. | |
3233 | ||
3234 | Generally, dangling objects aren't anything to worry about. They can | |
3235 | even be very useful: if you screw something up, the dangling objects can | |
3236 | be how you recover your old tree (say, you did a rebase, and realized | |
3237 | that you really didn't want to - you can look at what dangling objects | |
3238 | you have, and decide to reset your head to some old dangling state). | |
21dcb3b7 | 3239 | |
59723040 | 3240 | For commits, you can just use: |
21dcb3b7 BF |
3241 | |
3242 | ------------------------------------------------ | |
3243 | $ gitk <dangling-commit-sha-goes-here> --not --all | |
3244 | ------------------------------------------------ | |
3245 | ||
59723040 BF |
3246 | This asks for all the history reachable from the given commit but not |
3247 | from any branch, tag, or other reference. If you decide it's something | |
3248 | you want, you can always create a new reference to it, e.g., | |
3249 | ||
3250 | ------------------------------------------------ | |
3251 | $ git branch recovered-branch <dangling-commit-sha-goes-here> | |
3252 | ------------------------------------------------ | |
3253 | ||
3254 | For blobs and trees, you can't do the same, but you can still examine | |
3255 | them. You can just do | |
21dcb3b7 BF |
3256 | |
3257 | ------------------------------------------------ | |
3258 | $ git show <dangling-blob/tree-sha-goes-here> | |
3259 | ------------------------------------------------ | |
3260 | ||
1191ee18 BF |
3261 | to show what the contents of the blob were (or, for a tree, basically |
3262 | what the "ls" for that directory was), and that may give you some idea | |
3263 | of what the operation was that left that dangling object. | |
21dcb3b7 | 3264 | |
1191ee18 BF |
3265 | Usually, dangling blobs and trees aren't very interesting. They're |
3266 | almost always the result of either being a half-way mergebase (the blob | |
3267 | will often even have the conflict markers from a merge in it, if you | |
3268 | have had conflicting merges that you fixed up by hand), or simply | |
3269 | because you interrupted a "git fetch" with ^C or something like that, | |
3270 | leaving _some_ of the new objects in the object database, but just | |
3271 | dangling and useless. | |
21dcb3b7 BF |
3272 | |
3273 | Anyway, once you are sure that you're not interested in any dangling | |
3274 | state, you can just prune all unreachable objects: | |
3275 | ||
3276 | ------------------------------------------------ | |
3277 | $ git prune | |
3278 | ------------------------------------------------ | |
3279 | ||
1191ee18 BF |
3280 | and they'll be gone. But you should only run "git prune" on a quiescent |
3281 | repository - it's kind of like doing a filesystem fsck recovery: you | |
3282 | don't want to do that while the filesystem is mounted. | |
21dcb3b7 | 3283 | |
04e50e94 BF |
3284 | (The same is true of "git-fsck" itself, btw - but since |
3285 | git-fsck never actually *changes* the repository, it just reports | |
3286 | on what it found, git-fsck itself is never "dangerous" to run. | |
21dcb3b7 BF |
3287 | Running it while somebody is actually changing the repository can cause |
3288 | confusing and scary messages, but it won't actually do anything bad. In | |
3289 | contrast, running "git prune" while somebody is actively changing the | |
3290 | repository is a *BAD* idea). | |
3291 | ||
126640af | 3292 | [[birdview-on-the-source-code]] |
a5fc33b4 BF |
3293 | A birds-eye view of Git's source code |
3294 | ------------------------------------- | |
126640af | 3295 | |
a5fc33b4 BF |
3296 | It is not always easy for new developers to find their way through Git's |
3297 | source code. This section gives you a little guidance to show where to | |
3298 | start. | |
126640af | 3299 | |
a5fc33b4 | 3300 | A good place to start is with the contents of the initial commit, with: |
126640af JS |
3301 | |
3302 | ---------------------------------------------------- | |
a5fc33b4 | 3303 | $ git checkout e83c5163 |
126640af JS |
3304 | ---------------------------------------------------- |
3305 | ||
a5fc33b4 BF |
3306 | The initial revision lays the foundation for almost everything git has |
3307 | today, but is small enough to read in one sitting. | |
126640af | 3308 | |
a5fc33b4 BF |
3309 | Note that terminology has changed since that revision. For example, the |
3310 | README in that revision uses the word "changeset" to describe what we | |
3311 | now call a <<def_commit_object,commit>>. | |
126640af | 3312 | |
a5fc33b4 | 3313 | Also, we do not call it "cache" any more, but "index", however, the |
126640af JS |
3314 | file is still called `cache.h`. Remark: Not much reason to change it now, |
3315 | especially since there is no good single name for it anyway, because it is | |
3316 | basically _the_ header file which is included by _all_ of Git's C sources. | |
3317 | ||
a5fc33b4 BF |
3318 | If you grasp the ideas in that initial commit, you should check out a |
3319 | more recent version and skim `cache.h`, `object.h` and `commit.h`. | |
126640af JS |
3320 | |
3321 | In the early days, Git (in the tradition of UNIX) was a bunch of programs | |
3322 | which were extremely simple, and which you used in scripts, piping the | |
3323 | output of one into another. This turned out to be good for initial | |
3324 | development, since it was easier to test new things. However, recently | |
3325 | many of these parts have become builtins, and some of the core has been | |
3326 | "libified", i.e. put into libgit.a for performance, portability reasons, | |
3327 | and to avoid code duplication. | |
3328 | ||
3329 | By now, you know what the index is (and find the corresponding data | |
3330 | structures in `cache.h`), and that there are just a couple of object types | |
3331 | (blobs, trees, commits and tags) which inherit their common structure from | |
3332 | `struct object`, which is their first member (and thus, you can cast e.g. | |
3333 | `(struct object *)commit` to achieve the _same_ as `&commit->object`, i.e. | |
3334 | get at the object name and flags). | |
3335 | ||
3336 | Now is a good point to take a break to let this information sink in. | |
3337 | ||
3338 | Next step: get familiar with the object naming. Read <<naming-commits>>. | |
3339 | There are quite a few ways to name an object (and not only revisions!). | |
3340 | All of these are handled in `sha1_name.c`. Just have a quick look at | |
3341 | the function `get_sha1()`. A lot of the special handling is done by | |
3342 | functions like `get_sha1_basic()` or the likes. | |
3343 | ||
3344 | This is just to get you into the groove for the most libified part of Git: | |
3345 | the revision walker. | |
3346 | ||
3347 | Basically, the initial version of `git log` was a shell script: | |
3348 | ||
3349 | ---------------------------------------------------------------- | |
3350 | $ git-rev-list --pretty $(git-rev-parse --default HEAD "$@") | \ | |
3351 | LESS=-S ${PAGER:-less} | |
3352 | ---------------------------------------------------------------- | |
3353 | ||
3354 | What does this mean? | |
3355 | ||
3356 | `git-rev-list` is the original version of the revision walker, which | |
3357 | _always_ printed a list of revisions to stdout. It is still functional, | |
3358 | and needs to, since most new Git programs start out as scripts using | |
3359 | `git-rev-list`. | |
3360 | ||
3361 | `git-rev-parse` is not as important any more; it was only used to filter out | |
3362 | options that were relevant for the different plumbing commands that were | |
3363 | called by the script. | |
3364 | ||
3365 | Most of what `git-rev-list` did is contained in `revision.c` and | |
3366 | `revision.h`. It wraps the options in a struct named `rev_info`, which | |
3367 | controls how and what revisions are walked, and more. | |
3368 | ||
3369 | The original job of `git-rev-parse` is now taken by the function | |
3370 | `setup_revisions()`, which parses the revisions and the common command line | |
3371 | options for the revision walker. This information is stored in the struct | |
3372 | `rev_info` for later consumption. You can do your own command line option | |
3373 | parsing after calling `setup_revisions()`. After that, you have to call | |
3374 | `prepare_revision_walk()` for initialization, and then you can get the | |
3375 | commits one by one with the function `get_revision()`. | |
3376 | ||
3377 | If you are interested in more details of the revision walking process, | |
3378 | just have a look at the first implementation of `cmd_log()`; call | |
3379 | `git-show v1.3.0~155^2~4` and scroll down to that function (note that you | |
3380 | no longer need to call `setup_pager()` directly). | |
3381 | ||
3382 | Nowadays, `git log` is a builtin, which means that it is _contained_ in the | |
3383 | command `git`. The source side of a builtin is | |
3384 | ||
3385 | - a function called `cmd_<bla>`, typically defined in `builtin-<bla>.c`, | |
3386 | and declared in `builtin.h`, | |
3387 | ||
3388 | - an entry in the `commands[]` array in `git.c`, and | |
3389 | ||
3390 | - an entry in `BUILTIN_OBJECTS` in the `Makefile`. | |
3391 | ||
3392 | Sometimes, more than one builtin is contained in one source file. For | |
3393 | example, `cmd_whatchanged()` and `cmd_log()` both reside in `builtin-log.c`, | |
3394 | since they share quite a bit of code. In that case, the commands which are | |
3395 | _not_ named like the `.c` file in which they live have to be listed in | |
3396 | `BUILT_INS` in the `Makefile`. | |
3397 | ||
3398 | `git log` looks more complicated in C than it does in the original script, | |
3399 | but that allows for a much greater flexibility and performance. | |
3400 | ||
3401 | Here again it is a good point to take a pause. | |
3402 | ||
3403 | Lesson three is: study the code. Really, it is the best way to learn about | |
3404 | the organization of Git (after you know the basic concepts). | |
3405 | ||
3406 | So, think about something which you are interested in, say, "how can I | |
3407 | access a blob just knowing the object name of it?". The first step is to | |
3408 | find a Git command with which you can do it. In this example, it is either | |
3409 | `git show` or `git cat-file`. | |
3410 | ||
3411 | For the sake of clarity, let's stay with `git cat-file`, because it | |
3412 | ||
3413 | - is plumbing, and | |
3414 | ||
3415 | - was around even in the initial commit (it literally went only through | |
3416 | some 20 revisions as `cat-file.c`, was renamed to `builtin-cat-file.c` | |
3417 | when made a builtin, and then saw less than 10 versions). | |
3418 | ||
3419 | So, look into `builtin-cat-file.c`, search for `cmd_cat_file()` and look what | |
3420 | it does. | |
3421 | ||
3422 | ------------------------------------------------------------------ | |
3423 | git_config(git_default_config); | |
3424 | if (argc != 3) | |
3425 | usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>"); | |
3426 | if (get_sha1(argv[2], sha1)) | |
3427 | die("Not a valid object name %s", argv[2]); | |
3428 | ------------------------------------------------------------------ | |
3429 | ||
3430 | Let's skip over the obvious details; the only really interesting part | |
3431 | here is the call to `get_sha1()`. It tries to interpret `argv[2]` as an | |
3432 | object name, and if it refers to an object which is present in the current | |
3433 | repository, it writes the resulting SHA-1 into the variable `sha1`. | |
3434 | ||
3435 | Two things are interesting here: | |
3436 | ||
3437 | - `get_sha1()` returns 0 on _success_. This might surprise some new | |
3438 | Git hackers, but there is a long tradition in UNIX to return different | |
3439 | negative numbers in case of different errors -- and 0 on success. | |
3440 | ||
3441 | - the variable `sha1` in the function signature of `get_sha1()` is `unsigned | |
a5fc33b4 | 3442 | char \*`, but is actually expected to be a pointer to `unsigned |
126640af | 3443 | char[20]`. This variable will contain the 160-bit SHA-1 of the given |
a5fc33b4 | 3444 | commit. Note that whenever a SHA-1 is passed as `unsigned char \*`, it |
126640af | 3445 | is the binary representation, as opposed to the ASCII representation in |
a5fc33b4 | 3446 | hex characters, which is passed as `char *`. |
126640af JS |
3447 | |
3448 | You will see both of these things throughout the code. | |
3449 | ||
3450 | Now, for the meat: | |
3451 | ||
3452 | ----------------------------------------------------------------------------- | |
3453 | case 0: | |
3454 | buf = read_object_with_reference(sha1, argv[1], &size, NULL); | |
3455 | ----------------------------------------------------------------------------- | |
3456 | ||
3457 | This is how you read a blob (actually, not only a blob, but any type of | |
3458 | object). To know how the function `read_object_with_reference()` actually | |
3459 | works, find the source code for it (something like `git grep | |
3460 | read_object_with | grep ":[a-z]"` in the git repository), and read | |
3461 | the source. | |
3462 | ||
3463 | To find out how the result can be used, just read on in `cmd_cat_file()`: | |
3464 | ||
3465 | ----------------------------------- | |
3466 | write_or_die(1, buf, size); | |
3467 | ----------------------------------- | |
3468 | ||
3469 | Sometimes, you do not know where to look for a feature. In many such cases, | |
3470 | it helps to search through the output of `git log`, and then `git show` the | |
3471 | corresponding commit. | |
3472 | ||
3473 | Example: If you know that there was some test case for `git bundle`, but | |
3474 | do not remember where it was (yes, you _could_ `git grep bundle t/`, but that | |
3475 | does not illustrate the point!): | |
3476 | ||
3477 | ------------------------ | |
3478 | $ git log --no-merges t/ | |
3479 | ------------------------ | |
3480 | ||
3481 | In the pager (`less`), just search for "bundle", go a few lines back, | |
3482 | and see that it is in commit 18449ab0... Now just copy this object name, | |
3483 | and paste it into the command line | |
3484 | ||
3485 | ------------------- | |
3486 | $ git show 18449ab0 | |
3487 | ------------------- | |
3488 | ||
3489 | Voila. | |
3490 | ||
3491 | Another example: Find out what to do in order to make some script a | |
3492 | builtin: | |
3493 | ||
3494 | ------------------------------------------------- | |
3495 | $ git log --no-merges --diff-filter=A builtin-*.c | |
3496 | ------------------------------------------------- | |
3497 | ||
3498 | You see, Git is actually the best tool to find out about the source of Git | |
3499 | itself! | |
3500 | ||
e34caace | 3501 | [[glossary]] |
d19fbc3c BF |
3502 | include::glossary.txt[] |
3503 | ||
2624d9a5 BF |
3504 | [[git-quick-start]] |
3505 | Appendix A: Git Quick Start | |
3506 | =========================== | |
3507 | ||
3508 | This is a quick summary of the major commands; the following chapters | |
3509 | will explain how these work in more detail. | |
3510 | ||
3511 | [[quick-creating-a-new-repository]] | |
3512 | Creating a new repository | |
3513 | ------------------------- | |
3514 | ||
3515 | From a tarball: | |
3516 | ||
3517 | ----------------------------------------------- | |
3518 | $ tar xzf project.tar.gz | |
3519 | $ cd project | |
3520 | $ git init | |
3521 | Initialized empty Git repository in .git/ | |
3522 | $ git add . | |
3523 | $ git commit | |
3524 | ----------------------------------------------- | |
3525 | ||
3526 | From a remote repository: | |
3527 | ||
3528 | ----------------------------------------------- | |
3529 | $ git clone git://example.com/pub/project.git | |
3530 | $ cd project | |
3531 | ----------------------------------------------- | |
3532 | ||
3533 | [[managing-branches]] | |
3534 | Managing branches | |
3535 | ----------------- | |
3536 | ||
3537 | ----------------------------------------------- | |
3538 | $ git branch # list all local branches in this repo | |
3539 | $ git checkout test # switch working directory to branch "test" | |
3540 | $ git branch new # create branch "new" starting at current HEAD | |
3541 | $ git branch -d new # delete branch "new" | |
3542 | ----------------------------------------------- | |
3543 | ||
3544 | Instead of basing new branch on current HEAD (the default), use: | |
3545 | ||
3546 | ----------------------------------------------- | |
3547 | $ git branch new test # branch named "test" | |
3548 | $ git branch new v2.6.15 # tag named v2.6.15 | |
3549 | $ git branch new HEAD^ # commit before the most recent | |
3550 | $ git branch new HEAD^^ # commit before that | |
3551 | $ git branch new test~10 # ten commits before tip of branch "test" | |
3552 | ----------------------------------------------- | |
3553 | ||
3554 | Create and switch to a new branch at the same time: | |
3555 | ||
3556 | ----------------------------------------------- | |
3557 | $ git checkout -b new v2.6.15 | |
3558 | ----------------------------------------------- | |
3559 | ||
3560 | Update and examine branches from the repository you cloned from: | |
3561 | ||
3562 | ----------------------------------------------- | |
3563 | $ git fetch # update | |
3564 | $ git branch -r # list | |
3565 | origin/master | |
3566 | origin/next | |
3567 | ... | |
3568 | $ git checkout -b masterwork origin/master | |
3569 | ----------------------------------------------- | |
3570 | ||
3571 | Fetch a branch from a different repository, and give it a new | |
3572 | name in your repository: | |
3573 | ||
3574 | ----------------------------------------------- | |
3575 | $ git fetch git://example.com/project.git theirbranch:mybranch | |
3576 | $ git fetch git://example.com/project.git v2.6.15:mybranch | |
3577 | ----------------------------------------------- | |
3578 | ||
3579 | Keep a list of repositories you work with regularly: | |
3580 | ||
3581 | ----------------------------------------------- | |
3582 | $ git remote add example git://example.com/project.git | |
3583 | $ git remote # list remote repositories | |
3584 | example | |
3585 | origin | |
3586 | $ git remote show example # get details | |
3587 | * remote example | |
3588 | URL: git://example.com/project.git | |
3589 | Tracked remote branches | |
3590 | master next ... | |
3591 | $ git fetch example # update branches from example | |
3592 | $ git branch -r # list all remote branches | |
3593 | ----------------------------------------------- | |
3594 | ||
3595 | ||
3596 | [[exploring-history]] | |
3597 | Exploring history | |
3598 | ----------------- | |
3599 | ||
3600 | ----------------------------------------------- | |
3601 | $ gitk # visualize and browse history | |
3602 | $ git log # list all commits | |
3603 | $ git log src/ # ...modifying src/ | |
3604 | $ git log v2.6.15..v2.6.16 # ...in v2.6.16, not in v2.6.15 | |
3605 | $ git log master..test # ...in branch test, not in branch master | |
3606 | $ git log test..master # ...in branch master, but not in test | |
3607 | $ git log test...master # ...in one branch, not in both | |
3608 | $ git log -S'foo()' # ...where difference contain "foo()" | |
3609 | $ git log --since="2 weeks ago" | |
3610 | $ git log -p # show patches as well | |
3611 | $ git show # most recent commit | |
3612 | $ git diff v2.6.15..v2.6.16 # diff between two tagged versions | |
3613 | $ git diff v2.6.15..HEAD # diff with current head | |
3614 | $ git grep "foo()" # search working directory for "foo()" | |
3615 | $ git grep v2.6.15 "foo()" # search old tree for "foo()" | |
3616 | $ git show v2.6.15:a.txt # look at old version of a.txt | |
3617 | ----------------------------------------------- | |
3618 | ||
3619 | Search for regressions: | |
3620 | ||
3621 | ----------------------------------------------- | |
3622 | $ git bisect start | |
3623 | $ git bisect bad # current version is bad | |
3624 | $ git bisect good v2.6.13-rc2 # last known good revision | |
3625 | Bisecting: 675 revisions left to test after this | |
3626 | # test here, then: | |
3627 | $ git bisect good # if this revision is good, or | |
3628 | $ git bisect bad # if this revision is bad. | |
3629 | # repeat until done. | |
3630 | ----------------------------------------------- | |
3631 | ||
3632 | [[making-changes]] | |
3633 | Making changes | |
3634 | -------------- | |
3635 | ||
3636 | Make sure git knows who to blame: | |
3637 | ||
3638 | ------------------------------------------------ | |
3639 | $ cat >>~/.gitconfig <<\EOF | |
3640 | [user] | |
3641 | name = Your Name Comes Here | |
3642 | email = you@yourdomain.example.com | |
3643 | EOF | |
3644 | ------------------------------------------------ | |
3645 | ||
3646 | Select file contents to include in the next commit, then make the | |
3647 | commit: | |
3648 | ||
3649 | ----------------------------------------------- | |
3650 | $ git add a.txt # updated file | |
3651 | $ git add b.txt # new file | |
3652 | $ git rm c.txt # old file | |
3653 | $ git commit | |
3654 | ----------------------------------------------- | |
3655 | ||
3656 | Or, prepare and create the commit in one step: | |
3657 | ||
3658 | ----------------------------------------------- | |
3659 | $ git commit d.txt # use latest content only of d.txt | |
3660 | $ git commit -a # use latest content of all tracked files | |
3661 | ----------------------------------------------- | |
3662 | ||
3663 | [[merging]] | |
3664 | Merging | |
3665 | ------- | |
3666 | ||
3667 | ----------------------------------------------- | |
3668 | $ git merge test # merge branch "test" into the current branch | |
3669 | $ git pull git://example.com/project.git master | |
3670 | # fetch and merge in remote branch | |
3671 | $ git pull . test # equivalent to git merge test | |
3672 | ----------------------------------------------- | |
3673 | ||
3674 | [[sharing-your-changes]] | |
3675 | Sharing your changes | |
3676 | -------------------- | |
3677 | ||
3678 | Importing or exporting patches: | |
3679 | ||
3680 | ----------------------------------------------- | |
3681 | $ git format-patch origin..HEAD # format a patch for each commit | |
3682 | # in HEAD but not in origin | |
3683 | $ git am mbox # import patches from the mailbox "mbox" | |
3684 | ----------------------------------------------- | |
3685 | ||
3686 | Fetch a branch in a different git repository, then merge into the | |
3687 | current branch: | |
3688 | ||
3689 | ----------------------------------------------- | |
3690 | $ git pull git://example.com/project.git theirbranch | |
3691 | ----------------------------------------------- | |
3692 | ||
3693 | Store the fetched branch into a local branch before merging into the | |
3694 | current branch: | |
3695 | ||
3696 | ----------------------------------------------- | |
3697 | $ git pull git://example.com/project.git theirbranch:mybranch | |
3698 | ----------------------------------------------- | |
3699 | ||
3700 | After creating commits on a local branch, update the remote | |
3701 | branch with your commits: | |
3702 | ||
3703 | ----------------------------------------------- | |
3704 | $ git push ssh://example.com/project.git mybranch:theirbranch | |
3705 | ----------------------------------------------- | |
3706 | ||
3707 | When remote and local branch are both named "test": | |
3708 | ||
3709 | ----------------------------------------------- | |
3710 | $ git push ssh://example.com/project.git test | |
3711 | ----------------------------------------------- | |
3712 | ||
3713 | Shortcut version for a frequently used remote repository: | |
3714 | ||
3715 | ----------------------------------------------- | |
3716 | $ git remote add example ssh://example.com/project.git | |
3717 | $ git push example test | |
3718 | ----------------------------------------------- | |
3719 | ||
3720 | [[repository-maintenance]] | |
3721 | Repository maintenance | |
3722 | ---------------------- | |
3723 | ||
3724 | Check for corruption: | |
3725 | ||
3726 | ----------------------------------------------- | |
3727 | $ git fsck | |
3728 | ----------------------------------------------- | |
3729 | ||
3730 | Recompress, remove unused cruft: | |
3731 | ||
3732 | ----------------------------------------------- | |
3733 | $ git gc | |
3734 | ----------------------------------------------- | |
3735 | ||
3736 | ||
e34caace | 3737 | [[todo]] |
2624d9a5 BF |
3738 | Appendix B: Notes and todo list for this manual |
3739 | =============================================== | |
6bd9b682 BF |
3740 | |
3741 | This is a work in progress. | |
3742 | ||
3743 | The basic requirements: | |
2f99710c BF |
3744 | - It must be readable in order, from beginning to end, by |
3745 | someone intelligent with a basic grasp of the unix | |
3746 | commandline, but without any special knowledge of git. If | |
3747 | necessary, any other prerequisites should be specifically | |
3748 | mentioned as they arise. | |
3749 | - Whenever possible, section headings should clearly describe | |
3750 | the task they explain how to do, in language that requires | |
3751 | no more knowledge than necessary: for example, "importing | |
3752 | patches into a project" rather than "the git-am command" | |
6bd9b682 | 3753 | |
d5cd5de4 BF |
3754 | Think about how to create a clear chapter dependency graph that will |
3755 | allow people to get to important topics without necessarily reading | |
3756 | everything in between. | |
d19fbc3c | 3757 | |
aacd404e MC |
3758 | Say something about .gitignore. |
3759 | ||
d19fbc3c BF |
3760 | Scan Documentation/ for other stuff left out; in particular: |
3761 | howto's | |
d19fbc3c BF |
3762 | some of technical/? |
3763 | hooks | |
0b375ab0 | 3764 | list of commands in gitlink:git[1] |
d19fbc3c BF |
3765 | |
3766 | Scan email archives for other stuff left out | |
3767 | ||
3768 | Scan man pages to see if any assume more background than this manual | |
3769 | provides. | |
3770 | ||
2f99710c | 3771 | Simplify beginning by suggesting disconnected head instead of |
b181d57f | 3772 | temporary branch creation? |
d19fbc3c | 3773 | |
2f99710c BF |
3774 | Add more good examples. Entire sections of just cookbook examples |
3775 | might be a good idea; maybe make an "advanced examples" section a | |
3776 | standard end-of-chapter section? | |
d19fbc3c BF |
3777 | |
3778 | Include cross-references to the glossary, where appropriate. | |
3779 | ||
9a241220 BF |
3780 | Document shallow clones? See draft 1.5.0 release notes for some |
3781 | documentation. | |
3782 | ||
3dff5379 | 3783 | Add a section on working with other version control systems, including |
9a241220 BF |
3784 | CVS, Subversion, and just imports of series of release tarballs. |
3785 | ||
a8cd1402 | 3786 | More details on gitweb? |
0b375ab0 BF |
3787 | |
3788 | Write a chapter on using plumbing and writing scripts. |