Autogenerated HTML docs for v1.7.4.2-414-g07514
[git/jnareb-git.git] / gittutorial-2.html
blobe1405e189b2f0c19b974e27e2f33bb2eee67ba70
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.4.5" />
7 <title>gittutorial-2(7)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 gittutorial-2(7) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>gittutorial-2 -
411 A tutorial introduction to git: part two
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="paragraph"><p>git *</p></div>
418 </div>
419 <h2 id="_description">DESCRIPTION</h2>
420 <div class="sectionbody">
421 <div class="paragraph"><p>You should work through <a href="gittutorial.html">gittutorial(7)</a> before reading this tutorial.</p></div>
422 <div class="paragraph"><p>The goal of this tutorial is to introduce two fundamental pieces of
423 git&#8217;s architecture&#8212;the object database and the index file&#8212;and to
424 provide the reader with everything necessary to understand the rest
425 of the git documentation.</p></div>
426 </div>
427 <h2 id="_the_git_object_database">The git object database</h2>
428 <div class="sectionbody">
429 <div class="paragraph"><p>Let&#8217;s start a new project and create a small amount of history:</p></div>
430 <div class="listingblock">
431 <div class="content">
432 <pre><tt>$ mkdir test-project
433 $ cd test-project
434 $ git init
435 Initialized empty Git repository in .git/
436 $ echo 'hello world' &gt; file.txt
437 $ git add .
438 $ git commit -a -m "initial commit"
439 [master (root-commit) 54196cc] initial commit
440 1 files changed, 1 insertions(+), 0 deletions(-)
441 create mode 100644 file.txt
442 $ echo 'hello world!' &gt;file.txt
443 $ git commit -a -m "add emphasis"
444 [master c4d59f3] add emphasis
445 1 files changed, 1 insertions(+), 1 deletions(-)</tt></pre>
446 </div></div>
447 <div class="paragraph"><p>What are the 7 digits of hex that git responded to the commit with?</p></div>
448 <div class="paragraph"><p>We saw in part one of the tutorial that commits have names like this.
449 It turns out that every object in the git history is stored under
450 a 40-digit hex name. That name is the SHA1 hash of the object&#8217;s
451 contents; among other things, this ensures that git will never store
452 the same data twice (since identical data is given an identical SHA1
453 name), and that the contents of a git object will never change (since
454 that would change the object&#8217;s name as well). The 7 char hex strings
455 here are simply the abbreviation of such 40 character long strings.
456 Abbreviations can be used everywhere where the 40 character strings
457 can be used, so long as they are unambiguous.</p></div>
458 <div class="paragraph"><p>It is expected that the content of the commit object you created while
459 following the example above generates a different SHA1 hash than
460 the one shown above because the commit object records the time when
461 it was created and the name of the person performing the commit.</p></div>
462 <div class="paragraph"><p>We can ask git about this particular object with the <tt>cat-file</tt>
463 command. Don&#8217;t copy the 40 hex digits from this example but use those
464 from your own version. Note that you can shorten it to only a few
465 characters to save yourself typing all 40 hex digits:</p></div>
466 <div class="listingblock">
467 <div class="content">
468 <pre><tt>$ git cat-file -t 54196cc2
469 commit
470 $ git cat-file commit 54196cc2
471 tree 92b8b694ffb1675e5975148e1121810081dbdffe
472 author J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143414668 -0500
473 committer J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143414668 -0500
475 initial commit</tt></pre>
476 </div></div>
477 <div class="paragraph"><p>A tree can refer to one or more "blob" objects, each corresponding to
478 a file. In addition, a tree can also refer to other tree objects,
479 thus creating a directory hierarchy. You can examine the contents of
480 any tree using ls-tree (remember that a long enough initial portion
481 of the SHA1 will also work):</p></div>
482 <div class="listingblock">
483 <div class="content">
484 <pre><tt>$ git ls-tree 92b8b694
485 100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad file.txt</tt></pre>
486 </div></div>
487 <div class="paragraph"><p>Thus we see that this tree has one file in it. The SHA1 hash is a
488 reference to that file&#8217;s data:</p></div>
489 <div class="listingblock">
490 <div class="content">
491 <pre><tt>$ git cat-file -t 3b18e512
492 blob</tt></pre>
493 </div></div>
494 <div class="paragraph"><p>A "blob" is just file data, which we can also examine with cat-file:</p></div>
495 <div class="listingblock">
496 <div class="content">
497 <pre><tt>$ git cat-file blob 3b18e512
498 hello world</tt></pre>
499 </div></div>
500 <div class="paragraph"><p>Note that this is the old file data; so the object that git named in
501 its response to the initial tree was a tree with a snapshot of the
502 directory state that was recorded by the first commit.</p></div>
503 <div class="paragraph"><p>All of these objects are stored under their SHA1 names inside the git
504 directory:</p></div>
505 <div class="listingblock">
506 <div class="content">
507 <pre><tt>$ find .git/objects/
508 .git/objects/
509 .git/objects/pack
510 .git/objects/info
511 .git/objects/3b
512 .git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad
513 .git/objects/92
514 .git/objects/92/b8b694ffb1675e5975148e1121810081dbdffe
515 .git/objects/54
516 .git/objects/54/196cc2703dc165cbd373a65a4dcf22d50ae7f7
517 .git/objects/a0
518 .git/objects/a0/423896973644771497bdc03eb99d5281615b51
519 .git/objects/d0
520 .git/objects/d0/492b368b66bdabf2ac1fd8c92b39d3db916e59
521 .git/objects/c4
522 .git/objects/c4/d59f390b9cfd4318117afde11d601c1085f241</tt></pre>
523 </div></div>
524 <div class="paragraph"><p>and the contents of these files is just the compressed data plus a
525 header identifying their length and their type. The type is either a
526 blob, a tree, a commit, or a tag.</p></div>
527 <div class="paragraph"><p>The simplest commit to find is the HEAD commit, which we can find
528 from .git/HEAD:</p></div>
529 <div class="listingblock">
530 <div class="content">
531 <pre><tt>$ cat .git/HEAD
532 ref: refs/heads/master</tt></pre>
533 </div></div>
534 <div class="paragraph"><p>As you can see, this tells us which branch we&#8217;re currently on, and it
535 tells us this by naming a file under the .git directory, which itself
536 contains a SHA1 name referring to a commit object, which we can
537 examine with cat-file:</p></div>
538 <div class="listingblock">
539 <div class="content">
540 <pre><tt>$ cat .git/refs/heads/master
541 c4d59f390b9cfd4318117afde11d601c1085f241
542 $ git cat-file -t c4d59f39
543 commit
544 $ git cat-file commit c4d59f39
545 tree d0492b368b66bdabf2ac1fd8c92b39d3db916e59
546 parent 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
547 author J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143418702 -0500
548 committer J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143418702 -0500
550 add emphasis</tt></pre>
551 </div></div>
552 <div class="paragraph"><p>The "tree" object here refers to the new state of the tree:</p></div>
553 <div class="listingblock">
554 <div class="content">
555 <pre><tt>$ git ls-tree d0492b36
556 100644 blob a0423896973644771497bdc03eb99d5281615b51 file.txt
557 $ git cat-file blob a0423896
558 hello world!</tt></pre>
559 </div></div>
560 <div class="paragraph"><p>and the "parent" object refers to the previous commit:</p></div>
561 <div class="listingblock">
562 <div class="content">
563 <pre><tt>$ git cat-file commit 54196cc2
564 tree 92b8b694ffb1675e5975148e1121810081dbdffe
565 author J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143414668 -0500
566 committer J. Bruce Fields &lt;bfields@puzzle.fieldses.org&gt; 1143414668 -0500
568 initial commit</tt></pre>
569 </div></div>
570 <div class="paragraph"><p>The tree object is the tree we examined first, and this commit is
571 unusual in that it lacks any parent.</p></div>
572 <div class="paragraph"><p>Most commits have only one parent, but it is also common for a commit
573 to have multiple parents. In that case the commit represents a
574 merge, with the parent references pointing to the heads of the merged
575 branches.</p></div>
576 <div class="paragraph"><p>Besides blobs, trees, and commits, the only remaining type of object
577 is a "tag", which we won&#8217;t discuss here; refer to <a href="git-tag.html">git-tag(1)</a>
578 for details.</p></div>
579 <div class="paragraph"><p>So now we know how git uses the object database to represent a
580 project&#8217;s history:</p></div>
581 <div class="ulist"><ul>
582 <li>
584 "commit" objects refer to "tree" objects representing the
585 snapshot of a directory tree at a particular point in the
586 history, and refer to "parent" commits to show how they&#8217;re
587 connected into the project history.
588 </p>
589 </li>
590 <li>
592 "tree" objects represent the state of a single directory,
593 associating directory names to "blob" objects containing file
594 data and "tree" objects containing subdirectory information.
595 </p>
596 </li>
597 <li>
599 "blob" objects contain file data without any other structure.
600 </p>
601 </li>
602 <li>
604 References to commit objects at the head of each branch are
605 stored in files under .git/refs/heads/.
606 </p>
607 </li>
608 <li>
610 The name of the current branch is stored in .git/HEAD.
611 </p>
612 </li>
613 </ul></div>
614 <div class="paragraph"><p>Note, by the way, that lots of commands take a tree as an argument.
615 But as we can see above, a tree can be referred to in many different
616 ways&#8212;by the SHA1 name for that tree, by the name of a commit that
617 refers to the tree, by the name of a branch whose head refers to that
618 tree, etc.--and most such commands can accept any of these names.</p></div>
619 <div class="paragraph"><p>In command synopses, the word "tree-ish" is sometimes used to
620 designate such an argument.</p></div>
621 </div>
622 <h2 id="_the_index_file">The index file</h2>
623 <div class="sectionbody">
624 <div class="paragraph"><p>The primary tool we&#8217;ve been using to create commits is <tt>git-commit
625 -a</tt>, which creates a commit including every change you&#8217;ve made to
626 your working tree. But what if you want to commit changes only to
627 certain files? Or only certain changes to certain files?</p></div>
628 <div class="paragraph"><p>If we look at the way commits are created under the cover, we&#8217;ll see
629 that there are more flexible ways creating commits.</p></div>
630 <div class="paragraph"><p>Continuing with our test-project, let&#8217;s modify file.txt again:</p></div>
631 <div class="listingblock">
632 <div class="content">
633 <pre><tt>$ echo "hello world, again" &gt;&gt;file.txt</tt></pre>
634 </div></div>
635 <div class="paragraph"><p>but this time instead of immediately making the commit, let&#8217;s take an
636 intermediate step, and ask for diffs along the way to keep track of
637 what&#8217;s happening:</p></div>
638 <div class="listingblock">
639 <div class="content">
640 <pre><tt>$ git diff
641 --- a/file.txt
642 +++ b/file.txt
643 @@ -1 +1,2 @@
644 hello world!
645 +hello world, again
646 $ git add file.txt
647 $ git diff</tt></pre>
648 </div></div>
649 <div class="paragraph"><p>The last diff is empty, but no new commits have been made, and the
650 head still doesn&#8217;t contain the new line:</p></div>
651 <div class="listingblock">
652 <div class="content">
653 <pre><tt>$ git diff HEAD
654 diff --git a/file.txt b/file.txt
655 index a042389..513feba 100644
656 --- a/file.txt
657 +++ b/file.txt
658 @@ -1 +1,2 @@
659 hello world!
660 +hello world, again</tt></pre>
661 </div></div>
662 <div class="paragraph"><p>So <em>git diff</em> is comparing against something other than the head.
663 The thing that it&#8217;s comparing against is actually the index file,
664 which is stored in .git/index in a binary format, but whose contents
665 we can examine with ls-files:</p></div>
666 <div class="listingblock">
667 <div class="content">
668 <pre><tt>$ git ls-files --stage
669 100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt
670 $ git cat-file -t 513feba2
671 blob
672 $ git cat-file blob 513feba2
673 hello world!
674 hello world, again</tt></pre>
675 </div></div>
676 <div class="paragraph"><p>So what our <em>git add</em> did was store a new blob and then put
677 a reference to it in the index file. If we modify the file again,
678 we&#8217;ll see that the new modifications are reflected in the <em>git diff</em>
679 output:</p></div>
680 <div class="listingblock">
681 <div class="content">
682 <pre><tt>$ echo 'again?' &gt;&gt;file.txt
683 $ git diff
684 index 513feba..ba3da7b 100644
685 --- a/file.txt
686 +++ b/file.txt
687 @@ -1,2 +1,3 @@
688 hello world!
689 hello world, again
690 +again?</tt></pre>
691 </div></div>
692 <div class="paragraph"><p>With the right arguments, <em>git diff</em> can also show us the difference
693 between the working directory and the last commit, or between the
694 index and the last commit:</p></div>
695 <div class="listingblock">
696 <div class="content">
697 <pre><tt>$ git diff HEAD
698 diff --git a/file.txt b/file.txt
699 index a042389..ba3da7b 100644
700 --- a/file.txt
701 +++ b/file.txt
702 @@ -1 +1,3 @@
703 hello world!
704 +hello world, again
705 +again?
706 $ git diff --cached
707 diff --git a/file.txt b/file.txt
708 index a042389..513feba 100644
709 --- a/file.txt
710 +++ b/file.txt
711 @@ -1 +1,2 @@
712 hello world!
713 +hello world, again</tt></pre>
714 </div></div>
715 <div class="paragraph"><p>At any time, we can create a new commit using <em>git commit</em> (without
716 the "-a" option), and verify that the state committed only includes the
717 changes stored in the index file, not the additional change that is
718 still only in our working tree:</p></div>
719 <div class="listingblock">
720 <div class="content">
721 <pre><tt>$ git commit -m "repeat"
722 $ git diff HEAD
723 diff --git a/file.txt b/file.txt
724 index 513feba..ba3da7b 100644
725 --- a/file.txt
726 +++ b/file.txt
727 @@ -1,2 +1,3 @@
728 hello world!
729 hello world, again
730 +again?</tt></pre>
731 </div></div>
732 <div class="paragraph"><p>So by default <em>git commit</em> uses the index to create the commit, not
733 the working tree; the "-a" option to commit tells it to first update
734 the index with all changes in the working tree.</p></div>
735 <div class="paragraph"><p>Finally, it&#8217;s worth looking at the effect of <em>git add</em> on the index
736 file:</p></div>
737 <div class="listingblock">
738 <div class="content">
739 <pre><tt>$ echo "goodbye, world" &gt;closing.txt
740 $ git add closing.txt</tt></pre>
741 </div></div>
742 <div class="paragraph"><p>The effect of the <em>git add</em> was to add one entry to the index file:</p></div>
743 <div class="listingblock">
744 <div class="content">
745 <pre><tt>$ git ls-files --stage
746 100644 8b9743b20d4b15be3955fc8d5cd2b09cd2336138 0 closing.txt
747 100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt</tt></pre>
748 </div></div>
749 <div class="paragraph"><p>And, as you can see with cat-file, this new entry refers to the
750 current contents of the file:</p></div>
751 <div class="listingblock">
752 <div class="content">
753 <pre><tt>$ git cat-file blob 8b9743b2
754 goodbye, world</tt></pre>
755 </div></div>
756 <div class="paragraph"><p>The "status" command is a useful way to get a quick summary of the
757 situation:</p></div>
758 <div class="listingblock">
759 <div class="content">
760 <pre><tt>$ git status
761 # On branch master
762 # Changes to be committed:
763 # (use "git reset HEAD &lt;file&gt;..." to unstage)
765 # new file: closing.txt
767 # Changes not staged for commit:
768 # (use "git add &lt;file&gt;..." to update what will be committed)
770 # modified: file.txt
771 #</tt></pre>
772 </div></div>
773 <div class="paragraph"><p>Since the current state of closing.txt is cached in the index file,
774 it is listed as "Changes to be committed". Since file.txt has
775 changes in the working directory that aren&#8217;t reflected in the index,
776 it is marked "changed but not updated". At this point, running "git
777 commit" would create a commit that added closing.txt (with its new
778 contents), but that didn&#8217;t modify file.txt.</p></div>
779 <div class="paragraph"><p>Also, note that a bare <tt>git diff</tt> shows the changes to file.txt, but
780 not the addition of closing.txt, because the version of closing.txt
781 in the index file is identical to the one in the working directory.</p></div>
782 <div class="paragraph"><p>In addition to being the staging area for new commits, the index file
783 is also populated from the object database when checking out a
784 branch, and is used to hold the trees involved in a merge operation.
785 See <a href="gitcore-tutorial.html">gitcore-tutorial(7)</a> and the relevant man
786 pages for details.</p></div>
787 </div>
788 <h2 id="_what_next">What next?</h2>
789 <div class="sectionbody">
790 <div class="paragraph"><p>At this point you should know everything necessary to read the man
791 pages for any of the git commands; one good place to start would be
792 with the commands mentioned in <a href="everyday.html">Everyday git</a>. You
793 should be able to find any unknown jargon in <a href="gitglossary.html">gitglossary(7)</a>.</p></div>
794 <div class="paragraph"><p>The <a href="user-manual.html">Git User&#8217;s Manual</a> provides a more
795 comprehensive introduction to git.</p></div>
796 <div class="paragraph"><p><a href="gitcvs-migration.html">gitcvs-migration(7)</a> explains how to
797 import a CVS repository into git, and shows how to use git in a
798 CVS-like way.</p></div>
799 <div class="paragraph"><p>For some interesting examples of git use, see the
800 <a href="howto-index.html">howtos</a>.</p></div>
801 <div class="paragraph"><p>For git developers, <a href="gitcore-tutorial.html">gitcore-tutorial(7)</a> goes
802 into detail on the lower-level git mechanisms involved in, for
803 example, creating a new commit.</p></div>
804 </div>
805 <h2 id="_see_also">SEE ALSO</h2>
806 <div class="sectionbody">
807 <div class="paragraph"><p><a href="gittutorial.html">gittutorial(7)</a>,
808 <a href="gitcvs-migration.html">gitcvs-migration(7)</a>,
809 <a href="gitcore-tutorial.html">gitcore-tutorial(7)</a>,
810 <a href="gitglossary.html">gitglossary(7)</a>,
811 <a href="git-help.html">git-help(1)</a>,
812 <a href="everyday.html">Everyday git</a>,
813 <a href="user-manual.html">The Git User&#8217;s Manual</a></p></div>
814 </div>
815 <h2 id="_git">GIT</h2>
816 <div class="sectionbody">
817 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
818 </div>
819 <div id="footer">
820 <div id="footer-text">
821 Last updated 2010-11-25 03:13:43 UTC
822 </div>
823 </div>
824 </body>
825 </html>