Adjust core-git documentation to more recent Linus GIT.
[git.git] / Documentation / core-git.txt
1 This file contains reference information for the core git commands.
2
3 The README contains much useful definition and clarification
4 info - read that first.  And of the commands, I suggest reading
5 'git-update-cache' and 'git-read-tree' first - I wish I had!
6
7 David Greaves <david@dgreaves.com>
8 24/4/05
9
10 Updated by Junio C Hamano <junkio@cox.net> on 2005-05-05 to
11 reflect recent changes.
12
13 Identifier terminology used:
14
15 <object>
16         Indicates any object sha1 identifier
17
18 <blob>
19         Indicates a blob object sha1 identifier
20
21 <tree>
22         Indicates a tree object sha1 identifier
23
24 <commit>
25         Indicates a commit object sha1 identifier
26
27 <tree-ish>
28         Indicates a tree, commit or tag object sha1 identifier.
29         A command that takes a <tree-ish> argument ultimately
30         wants to operate on a <tree> object but automatically
31         dereferences <commit> and <tag> that points at a
32         <tree>.
33
34 <type>
35         Indicates that an object type is required.
36         Currently one of: blob/tree/commit/tag
37
38 <file>
39         Indicates a filename - always relative to the root of
40         the tree structure GIT_INDEX_FILE describes.
41
42
43 ################################################################
44 git-cat-file
45         git-cat-file (-t | <type>) <object>
46
47 Provides contents or type of objects in the repository. The type
48 is required if -t is not being used to find the object type.
49
50 <object>
51         The sha1 identifier of the object.
52
53 -t
54         Instead of the content, show the object type identified
55         by <object>.
56
57 <type>
58         Typically this matches the real type of <object> but
59         asking for type that can trivially dereferenced from the
60         given <object> is also permitted.  An example is to ask
61         "tree" with <object> for a commit object that contains
62         it, or to ask "blob" with <object> for a tag object that
63         points at it.
64
65 Output
66
67 If -t is specified, one of the <type>.
68
69 Otherwise the raw (though uncompressed) contents of the <object> will
70 be returned.
71
72
73 ################################################################
74 git-check-files
75         git-check-files <file>...
76
77 Check that a list of files are up-to-date between the filesystem and
78 the cache. Used to verify a patch target before doing a patch.
79
80 Files that do not exist on the filesystem are considered up-to-date
81 (whether or not they are in the cache).
82
83 Emits an error message on failure.
84 preparing to update existing file <file> not in cache
85           <file> exists but is not in the cache
86
87 preparing to update file <file> not uptodate in cache
88           <file> on disk is not up-to-date with the cache
89
90 Exits with a status code indicating success if all files are
91 up-to-date.
92
93 see also: git-update-cache
94
95
96 ################################################################
97 git-checkout-cache
98         git-checkout-cache [-q] [-a] [-f] [-n] [--prefix=<string>]
99                            [--] <file>...
100
101 Will copy all files listed from the cache to the working directory
102 (not overwriting existing files).
103
104 -q
105         be quiet if files exist or are not in the cache
106
107 -f
108         forces overwrite of existing files
109
110 -a
111         checks out all files in the cache (will then continue to
112         process listed files).
113
114 -n
115         Don't checkout new files, only refresh files already checked
116         out.
117
118 --prefix=<string>
119         When creating files, prepend <string> (usually a directory
120         including a trailing /)
121
122 --
123         Do not interpret any more arguments as options.
124
125 Note that the order of the flags matters:
126
127         git-checkout-cache -a -f file.c
128
129 will first check out all files listed in the cache (but not overwrite
130 any old ones), and then force-checkout file.c a second time (ie that
131 one _will_ overwrite any old contents with the same filename).
132
133 Also, just doing "git-checkout-cache" does nothing. You probably meant
134 "git-checkout-cache -a". And if you want to force it, you want
135 "git-checkout-cache -f -a".
136
137 Intuitiveness is not the goal here. Repeatability is. The reason for
138 the "no arguments means no work" thing is that from scripts you are
139 supposed to be able to do things like
140
141         find . -name '*.h' -print0 | xargs -0 git-checkout-cache -f --
142
143 which will force all existing *.h files to be replaced with their
144 cached copies. If an empty command line implied "all", then this would
145 force-refresh everything in the cache, which was not the point.
146
147 To update and refresh only the files already checked out:
148
149    git-checkout-cache -n -f -a && git-update-cache --ignore-missing --refresh
150
151 Oh, and the "--" is just a good idea when you know the rest will be
152 filenames. Just so that you wouldn't have a filename of "-a" causing
153 problems (not possible in the above example, but get used to it in
154 scripting!).
155
156 The prefix ability basically makes it trivial to use git-checkout-cache as
157 a "git-export as tree" function. Just read the desired tree into the
158 index, and do a
159   
160         git-checkout-cache --prefix=git-export-dir/ -a
161   
162 and git-checkout-cache will "git-export" the cache into the specified
163 directory.
164   
165 NOTE! The final "/" is important. The git-exported name is literally just
166 prefixed with the specified string, so you can also do something like
167   
168         git-checkout-cache --prefix=.merged- Makefile
169   
170 to check out the currently cached copy of "Makefile" into the file
171 ".merged-Makefile".
172
173
174 ################################################################
175 git-commit-tree
176         git-commit-tree <tree> [-p <parent commit>]*   < changelog
177
178 Creates a new commit object based on the provided tree object and
179 emits the new commit object id on stdout. If no parent is given then
180 it is considered to be an initial tree.
181
182 A commit object usually has 1 parent (a commit after a change) or up
183 to 16 parents.  More than one parent represents a merge of branches
184 that led to them.
185
186 While a tree represents a particular directory state of a working
187 directory, a commit represents that state in "time", and explains how
188 to get there.
189
190 Normally a commit would identify a new "HEAD" state, and while git
191 doesn't care where you save the note about that state, in practice we
192 tend to just write the result to the file ".git/HEAD", so that we can
193 always see what the last committed state was.
194
195 Options
196
197 <tree>
198         An existing tree object
199
200 -p <parent commit>
201         Each -p indicates a the id of a parent commit object.
202         
203
204 Commit Information
205
206 A commit encapsulates:
207         all parent object ids
208         author name, email and date
209         committer name and email and the commit time.
210
211 If not provided, git-commit-tree uses your name, hostname and domain to
212 provide author and committer info. This can be overridden using the
213 following environment variables.
214         AUTHOR_NAME
215         AUTHOR_EMAIL
216         AUTHOR_DATE
217         COMMIT_AUTHOR_NAME
218         COMMIT_AUTHOR_EMAIL
219 (nb <,> and '\n's are stripped)
220
221 A commit comment is read from stdin (max 999 chars). If a changelog
222 entry is not provided via '<' redirection, git-commit-tree will just wait
223 for one to be entered and terminated with ^D
224
225 see also: git-write-tree
226
227
228 ################################################################
229 git-diff-cache
230         git-diff-cache [-p] [-r] [-z] [--cached] <tree-ish>
231
232 Compares the content and mode of the blobs found via a tree object
233 with the content of the current cache and, optionally ignoring the
234 stat state of the file on disk.
235
236 <tree-ish>
237         The id of a tree object to diff against.
238
239 -p
240         Generate patch (see section on generating patches)
241
242 -r
243         This flag does not mean anything.  It is there only to match
244         git-diff-tree.  Unlike git-diff-tree, git-diff-cache always looks
245         at all the subdirectories.
246
247 -z
248         \0 line termination on output
249
250 --cached
251         do not consider the on-disk file at all
252
253 Output format:
254
255 See "Output format from git-diff-cache, git-diff-tree and git-diff-files"
256 section.
257
258 Operating Modes
259
260 You can choose whether you want to trust the index file entirely
261 (using the "--cached" flag) or ask the diff logic to show any files
262 that don't match the stat state as being "tentatively changed".  Both
263 of these operations are very useful indeed.
264
265 Cached Mode
266
267 If --cached is specified, it allows you to ask:
268
269         show me the differences between HEAD and the current index
270         contents (the ones I'd write with a "git-write-tree")
271
272 For example, let's say that you have worked on your index file, and are
273 ready to commit. You want to see eactly _what_ you are going to commit is
274 without having to write a new tree object and compare it that way, and to
275 do that, you just do
276
277         git-diff-cache --cached $(cat .git/HEAD)
278
279 Example: let's say I had renamed "commit.c" to "git-commit.c", and I had
280 done an "git-update-cache" to make that effective in the index file.
281 "git-diff-files" wouldn't show anything at all, since the index file
282 matches my working directory. But doing a git-diff-cache does:
283
284   torvalds@ppc970:~/git> git-diff-cache --cached $(cat .git/HEAD)
285   -100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        commit.c
286   +100644 blob    4161aecc6700a2eb579e842af0b7f22b98443f74        git-commit.c
287
288 You can trivially see that the above is a rename.
289
290 In fact, "git-diff-cache --cached" _should_ always be entirely equivalent to
291 actually doing a "git-write-tree" and comparing that. Except this one is much
292 nicer for the case where you just want to check where you are.
293
294 So doing a "git-diff-cache --cached" is basically very useful when you are 
295 asking yourself "what have I already marked for being committed, and 
296 what's the difference to a previous tree".
297
298 Non-cached Mode
299
300 The "non-cached" mode takes a different approach, and is potentially the
301 even more useful of the two in that what it does can't be emulated with a
302 "git-write-tree + git-diff-tree". Thus that's the default mode.  The
303 non-cached version asks the question
304
305    "show me the differences between HEAD and the currently checked out 
306     tree - index contents _and_ files that aren't up-to-date"
307
308 which is obviously a very useful question too, since that tells you what
309 you _could_ commit. Again, the output matches the "git-diff-tree -r"
310 output to a tee, but with a twist.
311
312 The twist is that if some file doesn't match the cache, we don't have a
313 backing store thing for it, and we use the magic "all-zero" sha1 to show
314 that. So let's say that you have edited "kernel/sched.c", but have not
315 actually done an git-update-cache on it yet - there is no "object" associated
316 with the new state, and you get:
317
318   torvalds@ppc970:~/v2.6/linux> git-diff-cache $(cat .git/HEAD )
319   *100644->100664 blob    7476bb......->000000......      kernel/sched.c
320
321 ie it shows that the tree has changed, and that "kernel/sched.c" has is
322 not up-to-date and may contain new stuff. The all-zero sha1 means that to
323 get the real diff, you need to look at the object in the working directory
324 directly rather than do an object-to-object diff.
325
326 NOTE! As with other commands of this type, "git-diff-cache" does not
327 actually look at the contents of the file at all. So maybe
328 "kernel/sched.c" hasn't actually changed, and it's just that you touched
329 it. In either case, it's a note that you need to upate-cache it to make
330 the cache be in sync.
331
332 NOTE 2! You can have a mixture of files show up as "has been updated" and
333 "is still dirty in the working directory" together. You can always tell
334 which file is in which state, since the "has been updated" ones show a
335 valid sha1, and the "not in sync with the index" ones will always have the
336 special all-zero sha1.
337
338 ################################################################
339 git-diff-tree
340         git-diff-tree [-p] [-r] [-z] <tree-ish> <tree-ish> [<pattern>]*
341
342 Compares the content and mode of the blobs found via two tree objects.
343
344 Note that git-diff-tree can use the tree encapsulated in a commit object.
345
346 <tree-ish>
347         The id of a tree object.
348
349 <pattern>
350         If provided, the results are limited to a subset of files
351         matching one of these prefix strings.
352         ie file matches /^<pattern1>|<pattern2>|.../
353         Note that pattern does not provide any wildcard or regexp
354         features.
355
356 -p
357         generate patch (see section on generating patches).  For
358         git-diff-tree, this flag implies -r as well.
359
360 -r
361         recurse
362
363 -z
364         \0 line termination on output
365
366 Limiting Output
367
368 If you're only interested in differences in a subset of files, for
369 example some architecture-specific files, you might do:
370
371         git-diff-tree -r <tree-ish> <tree-ish> arch/ia64 include/asm-ia64
372
373 and it will only show you what changed in those two directories.
374
375 Or if you are searching for what changed in just kernel/sched.c, just do
376
377         git-diff-tree -r <tree-ish> <tree-ish> kernel/sched.c
378
379 and it will ignore all differences to other files.
380
381 The pattern is always the prefix, and is matched exactly.  There are no
382 wildcards.  Even stricter, it has to match complete path comonent.
383 I.e. "foo" does not pick up "foobar.h".  "foo" does match "foo/bar.h"
384 so it can be used to name subdirectories.
385
386 Output format:
387
388 See "Output format from git-diff-cache, git-diff-tree and git-diff-files"
389 section.
390
391 An example of normal usage is:
392
393   torvalds@ppc970:~/git> git-diff-tree 5319e4......
394   *100664->100664 blob    ac348b.......->a01513.......      git-fsck-cache.c
395
396 which tells you that the last commit changed just one file (it's from
397 this one:
398
399   commit 3c6f7ca19ad4043e9e72fa94106f352897e651a8
400   tree 5319e4d609cdd282069cc4dce33c1db559539b03
401   parent b4e628ea30d5ab3606119d2ea5caeab141d38df7
402   author Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
403   committer Linus Torvalds <torvalds@ppc970.osdl.org> Sat Apr 9 12:02:30 2005
404
405   Make "git-fsck-cache" print out all the root commits it finds.
406
407   Once I do the reference tracking, I'll also make it print out all the
408   HEAD commits it finds, which is even more interesting.
409
410 in case you care).
411
412 ################################################################
413 git-diff-tree-helper
414         git-diff-tree-helper [-z] [-R]
415
416 Reads output from git-diff-cache, git-diff-tree and git-diff-files and
417 generates patch format output.
418
419 -z
420         \0 line termination on input
421
422 -R
423         Output diff in reverse.  This is useful for displaying output from
424         git-diff-cache which always compares tree with cache or working
425         file.  E.g.
426
427         git-diff-cache <tree> | git-diff-tree-helper -R file.c
428
429         would show a diff to bring the working file back to what is in the
430         <tree>.
431
432 See also the section on generating patches.
433
434 ################################################################
435 git-fsck-cache
436         git-fsck-cache [--tags] [--root] [[--unreachable] [--cache] <object>*]
437
438 Verifies the connectivity and validity of the objects in the database.
439
440 <object>
441         An object to treat as the head of an unreachability trace.
442
443 --unreachable
444         Print out objects that exist but that aren't readable from any
445         of the specified head nodes.
446
447 --root
448         Report root nodes.
449
450 --tags
451         Report tags.
452
453 --cache
454         Consider any object recorded in the cache also as a head node for
455         an unreachability trace.
456
457 It tests SHA1 and general object sanity, and it does full tracking of
458 the resulting reachability and everything else. It prints out any
459 corruption it finds (missing or bad objects), and if you use the
460 "--unreachable" flag it will also print out objects that exist but
461 that aren't readable from any of the specified head nodes.
462
463 So for example
464
465         git-fsck-cache --unreachable $(cat .git/HEAD)
466
467 or, for Cogito users:
468
469         git-fsck-cache --unreachable $(cat .git/refs/heads/*)
470
471 will do quite a _lot_ of verification on the tree. There are a few
472 extra validity tests to be added (make sure that tree objects are
473 sorted properly etc), but on the whole if "git-fsck-cache" is happy, you
474 do have a valid tree.
475
476 Any corrupt objects you will have to find in backups or other archives
477 (ie you can just remove them and do an "rsync" with some other site in
478 the hopes that somebody else has the object you have corrupted).
479
480 Of course, "valid tree" doesn't mean that it wasn't generated by some
481 evil person, and the end result might be crap. Git is a revision
482 tracking system, not a quality assurance system ;)
483
484 Extracted Diagnostics
485
486 expect dangling commits - potential heads - due to lack of head information
487         You haven't specified any nodes as heads so it won't be
488         possible to differentiate between un-parented commits and
489         root nodes.
490
491 missing sha1 directory '<dir>'
492         The directory holding the sha1 objects is missing.
493
494 unreachable <type> <object>
495         The <type> object <object>, isn't actually referred to directly
496         or indirectly in any of the trees or commits seen. This can
497         mean that there's another root na SHA1_ode that you're not specifying
498         or that the tree is corrupt. If you haven't missed a root node
499         then you might as well delete unreachable nodes since they
500         can't be used.
501
502 missing <type> <object>
503         The <type> object <object>, is referred to but isn't present in
504         the database.
505
506 dangling <type> <object>
507         The <type> object <object>, is present in the database but never
508         _directly_ used. A dangling commit could be a root node.
509
510 warning: git-fsck-cache: tree <tree> has full pathnames in it
511         And it shouldn't...
512
513 sha1 mismatch <object>
514         The database has an object who's sha1 doesn't match the
515         database value.
516         This indicates a ??serious?? data integrity problem.
517         (note: this error occured during early git development when
518         the database format changed.)
519
520 Environment Variables
521
522 SHA1_FILE_DIRECTORY
523         used to specify the object database root (usually .git/objects)
524
525 GIT_INDEX_FILE
526         used to specify the cache
527
528 ################################################################
529 git-export
530         git-export top [base]
531
532 Exports each commit and diff against each of its parents, between
533 top and base.  If base is not specified it exports everything.
534
535
536 ################################################################
537 git-init-db
538         git-init-db
539
540 This simply creates an empty git object database - basically a .git
541 directory and .git/object/??/ directories.
542
543 If the object storage directory is specified via the SHA1_FILE_DIRECTORY
544 environment variable then the sha1 directories are created underneath -
545 otherwise the default .git/objects directory is used.
546
547 git-init-db won't hurt an existing repository.
548
549
550 ################################################################
551 git-ls-tree
552         git-ls-tree [-r] [-z] <tree-ish>
553
554 Converts the tree object to a human readable (and script processable)
555 form.
556
557 <tree-ish>
558         Id of a tree.
559
560 -r
561         recurse into sub-trees
562
563 -z
564         \0 line termination on output
565
566 Output Format
567 <mode>\t        <type>\t        <object>\t      <file>
568
569
570 ################################################################
571 git-merge-base
572         git-merge-base <commit> <commit>
573
574 git-merge-base finds as good a common ancestor as possible. Given a
575 selection of equally good common ancestors it should not be relied on
576 to decide in any particular way.
577
578 The git-merge-base algorithm is still in flux - use the source...
579
580
581 ################################################################
582 git-merge-cache
583         git-merge-cache <merge-program> (-a | -- | <file>*) 
584
585 This looks up the <file>(s) in the cache and, if there are any merge
586 entries, passes the SHA1 hash for those files as arguments 1, 2, 3 (empty
587 argument if no file), and <file> as argument 4.  File modes for the three
588 files are passed as arguments 5, 6 and 7.
589
590 --
591         Interpret all future arguments as filenames.
592
593 -a
594         Run merge against all files in the cache that need merging.
595
596 If git-merge-cache is called with multiple <file>s (or -a) then it
597 processes them in turn only stopping if merge returns a non-zero exit
598 code.
599
600 Typically this is run with the a script calling the merge command from
601 the RCS package.
602
603 A sample script called git-merge-one-file-script is included in the
604 ditribution.
605
606 ALERT ALERT ALERT! The git "merge object order" is different from the
607 RCS "merge" program merge object order. In the above ordering, the
608 original is first. But the argument order to the 3-way merge program
609 "merge" is to have the original in the middle. Don't ask me why.
610
611 Examples:
612
613   torvalds@ppc970:~/merge-test> git-merge-cache cat MM
614   This is MM from the original tree.                    # original
615   This is modified MM in the branch A.                  # merge1
616   This is modified MM in the branch B.                  # merge2
617   This is modified MM in the branch B.                  # current contents
618
619 or 
620
621   torvalds@ppc970:~/merge-test> git-merge-cache cat AA MM
622   cat: : No such file or directory
623   This is added AA in the branch A.
624   This is added AA in the branch B.
625   This is added AA in the branch B.
626   fatal: merge program failed
627
628 where the latter example shows how "git-merge-cache" will stop trying to
629 merge once anything has returned an error (ie "cat" returned an error
630 for the AA file, because it didn't exist in the original, and thus
631 "git-merge-cache" didn't even try to merge the MM thing).
632
633
634 ################################################################
635 git-read-tree
636         git-read-tree (<tree-ish> | -m <tree-ish1> [<tree-ish2> <tree-ish3>])"
637
638 Reads the tree information given by <tree> into the directory cache,
639 but does not actually _update_ any of the files it "caches". (see:
640 git-checkout-cache)
641
642 Optionally, it can merge a tree into the cache or perform a 3-way
643 merge.
644
645 Trivial merges are done by git-read-tree itself.  Only conflicting paths
646 will be in unmerged state when git-read-tree returns.
647
648 -m
649         Perform a merge, not just a read
650
651 <tree-ish#>
652         The id of the tree object(s) to be read/merged.
653
654
655 Merging
656 If -m is specified, git-read-tree performs 2 kinds of merge, a single tree
657 merge if only 1 tree is given or a 3-way merge if 3 trees are
658 provided.
659
660 Single Tree Merge
661 If only 1 tree is specified, git-read-tree operates as if the user did not
662 specify "-m", except that if the original cache has an entry for a
663 given pathname; and the contents of the path matches with the tree
664 being read, the stat info from the cache is used. (In other words, the
665 cache's stat()s take precedence over the merged tree's)
666
667 That means that if you do a "git-read-tree -m <newtree>" followed by a
668 "git-checkout-cache -f -a", the git-checkout-cache only checks out the stuff
669 that really changed.
670
671 This is used to avoid unnecessary false hits when git-diff-files is
672 run after git-read-tree.
673
674 3-Way Merge
675 Each "index" entry has two bits worth of "stage" state. stage 0 is the
676 normal one, and is the only one you'd see in any kind of normal use.
677
678 However, when you do "git-read-tree" with three trees, the "stage"
679 starts out at 1.
680
681 This means that you can do
682
683         git-read-tree -m <tree1> <tree2> <tree3>
684
685 and you will end up with an index with all of the <tree1> entries in
686 "stage1", all of the <tree2> entries in "stage2" and all of the
687 <tree3> entries in "stage3".
688
689 Furthermore, "git-read-tree" has special-case logic that says: if you see
690 a file that matches in all respects in the following states, it
691 "collapses" back to "stage0":
692
693    - stage 2 and 3 are the same; take one or the other (it makes no
694      difference - the same work has been done on stage 2 and 3)
695
696    - stage 1 and stage 2 are the same and stage 3 is different; take
697      stage 3 (some work has been done on stage 3)
698
699    - stage 1 and stage 3 are the same and stage 2 is different take
700      stage 2 (some work has been done on stage 2)
701
702 The git-write-tree command refuses to write a nonsensical tree, and it
703 will complain about unmerged entries if it sees a single entry that is not
704 stage 0.
705
706 Ok, this all sounds like a collection of totally nonsensical rules,
707 but it's actually exactly what you want in order to do a fast
708 merge. The different stages represent the "result tree" (stage 0, aka
709 "merged"), the original tree (stage 1, aka "orig"), and the two trees
710 you are trying to merge (stage 2 and 3 respectively).
711
712 In fact, the way "git-read-tree" works, it's entirely agnostic about how
713 you assign the stages, and you could really assign them any which way,
714 and the above is just a suggested way to do it (except since
715 "git-write-tree" refuses to write anything but stage0 entries, it makes
716 sense to always consider stage 0 to be the "full merge" state).
717
718 So what happens? Try it out. Select the original tree, and two trees
719 to merge, and look how it works:
720
721  - if a file exists in identical format in all three trees, it will 
722    automatically collapse to "merged" state by the new git-read-tree.
723
724  - a file that has _any_ difference what-so-ever in the three trees
725    will stay as separate entries in the index. It's up to "script
726    policy" to determine how to remove the non-0 stages, and insert a
727    merged version.  But since the index is always sorted, they're easy
728    to find: they'll be clustered together.
729
730  - the index file saves and restores with all this information, so you
731    can merge things incrementally, but as long as it has entries in
732    stages 1/2/3 (ie "unmerged entries") you can't write the result.
733
734 So now the merge algorithm ends up being really simple:
735
736  - you walk the index in order, and ignore all entries of stage 0,
737    since they've already been done.
738
739  - if you find a "stage1", but no matching "stage2" or "stage3", you
740    know it's been removed from both trees (it only existed in the
741    original tree), and you remove that entry.  - if you find a
742    matching "stage2" and "stage3" tree, you remove one of them, and
743    turn the other into a "stage0" entry. Remove any matching "stage1"
744    entry if it exists too.  .. all the normal trivial rules ..
745
746 Incidentally - it also means that you don't even have to have a separate
747 subdirectory for this. All the information literally is in the index file,
748 which is a temporary thing anyway. There is no need to worry about what is
749 in the working directory, since it is never shown and never used.
750
751 see also:
752 git-write-tree
753 git-ls-files
754
755
756 ################################################################
757 git-rev-list <commit>
758
759 Lists commit objects in reverse chronological order starting at the
760 given commit, taking ancestry relationship into account.  This is
761 useful to produce human-readable log output.
762
763
764 ################################################################
765 git-rev-tree
766         git-rev-tree [--edges] [--cache <cache-file>] [^]<commit> [[^]<commit>]
767
768 Provides the revision tree for one or more commits.
769
770 --edges
771         Show edges (ie places where the marking changes between parent
772         and child)
773
774 --cache <cache-file>
775         Use the specified file as a cache from a previous git-rev-list run
776         to speed things up.  Note that this "cache" is totally different
777         concept from the directory index.  Also this option is not
778         implemented yet.
779
780 [^]<commit>
781         The commit id to trace (a leading caret means to ignore this
782         commit-id and below)
783
784 Output:
785 <date> <commit>:<flags> [<parent-commit>:<flags> ]*
786
787 <date>
788         Date in 'seconds since epoch'
789
790 <commit>
791         id of commit object
792
793 <parent-commit>
794         id of each parent commit object (>1 indicates a merge)
795
796 <flags>
797
798         The flags are read as a bitmask representing each commit
799         provided on the commandline. eg: given the command:
800
801                  $ git-rev-tree <com1> <com2> <com3>
802
803         The output:
804
805             <date> <commit>:5
806
807          means that <commit> is reachable from <com1>(1) and <com3>(4)
808         
809 A revtree can get quite large. git-rev-tree will eventually allow you to
810 cache previous state so that you don't have to follow the whole thing
811 down.
812
813 So the change difference between two commits is literally
814
815         git-rev-tree [commit-id1]  > commit1-revtree
816         git-rev-tree [commit-id2]  > commit2-revtree
817         join -t : commit1-revtree commit2-revtree > common-revisions
818
819 (this is also how to find the most common parent - you'd look at just
820 the head revisions - the ones that aren't referred to by other
821 revisions - in "common-revision", and figure out the best one. I
822 think.)
823
824
825 ################################################################
826 git-diff-files
827         git-diff-files [-p] [-q] [-r] [-z] [<pattern>...]
828
829 Compares the files in the working tree and the cache.  When paths
830 are specified, compares only those named paths.  Otherwise all
831 entries in the cache are compared.  The output format is the
832 same as git-diff-cache and git-diff-tree.
833
834 -p
835         generate patch (see section on generating patches).
836
837 -q
838         Remain silent even on nonexisting files
839
840 -r
841         This flag does not mean anything.  It is there only to match
842         git-diff-tree.  Unlike git-diff-tree, git-diff-files always looks
843         at all the subdirectories.
844
845
846 Output format:
847
848 See "Output format from git-diff-cache, git-diff-tree and git-diff-files"
849 section.
850
851
852 ################################################################
853 git-ls-files
854         git-ls-files [-z] [-t]
855                 (--[cached|deleted|others|ignored|stage|unmerged])*
856                 (-[c|d|o|i|s|u])*
857                 [-x <pattern>|--exclude=<pattern>]
858                 [-X <file>|--exclude-from=<file>]
859
860 This merges the file listing in the directory cache index with the
861 actual working directory list, and shows different combinations of the
862 two.
863
864 One or more of the options below may be used to determine the files
865 shown:
866
867 -c|--cached
868         Show cached files in the output (default)
869
870 -d|--deleted
871         Show deleted files in the output
872
873 -o|--others
874         Show other files in the output
875
876 -i|--ignored
877         Show ignored files in the output
878         Note the this also reverses any exclude list present.
879
880 -s|--stage
881         Show stage files in the output
882
883 -u|--unmerged
884         Show unmerged files in the output (forces --stage)
885
886 -z
887         \0 line termination on output
888
889 -x|--exclude=<pattern>
890         Skips files matching pattern.
891         Note that pattern is a shell wildcard pattern.
892
893 -X|--exclude-from=<file>
894         exclude patterns are read from <file>; 1 per line.
895         Allows the use of the famous dontdiff file as follows to find
896         out about uncommitted files just as dontdiff is used with
897         the diff command:
898              git-ls-files --others --exclude-from=dontdiff
899
900 Output
901 show files just outputs the filename unless --stage is specified in
902 which case it outputs:
903
904 [<tag> ]<mode> <object> <stage> <file>
905
906 git-ls-files --unmerged" and "git-ls-files --stage " can be used to examine
907 detailed information on unmerged paths.
908
909 For an unmerged path, instead of recording a single mode/SHA1 pair,
910 the dircache records up to three such pairs; one from tree O in stage
911 1, A in stage 2, and B in stage 3.  This information can be used by
912 the user (or Cogito) to see what should eventually be recorded at the
913 path. (see read-cache for more information on state)
914
915 see also:
916 read-cache
917
918
919 ################################################################
920 git-unpack-file
921         git-unpack-file <blob>
922
923 Creates a file holding the contents of the blob specified by sha1. It
924 returns the name of the temporary file in the following format:
925         .merge_file_XXXXX
926
927 <blob>
928         Must be a blob id
929
930 ################################################################
931 git-update-cache
932         git-update-cache
933              [--add] [--remove] [--refresh]
934              [--ignore-missing]
935              [--force-remove <file>]
936              [--cacheinfo <mode> <object> <file>]*
937              [--] [<file>]*
938
939 Modifies the index or directory cache. Each file mentioned is updated
940 into the cache and any 'unmerged' or 'needs updating' state is
941 cleared.
942
943 The way git-update-cache handles files it is told about can be modified
944 using the various options:
945
946 --add
947         If a specified file isn't in the cache already then it's
948         added.
949         Default behaviour is to ignore new files.
950
951 --remove
952         If a specified file is in the cache but is missing then it's
953         removed.
954         Default behaviour is to ignore removed file.
955
956 --refresh
957         Looks at the current cache and checks to see if merges or
958         updates are needed by checking stat() information.
959
960 --ignore-missing
961         Ignores missing files during a --refresh
962
963 --cacheinfo <mode> <object> <path>
964         Directly insert the specified info into the cache.
965         
966 --force-remove
967         Remove the file from the index even when the working directory
968         still has such a file.
969
970 --
971         Do not interpret any more arguments as options.
972
973 <file>
974         Files to act on.
975         Note that files begining with '.' are discarded. This includes
976         "./file" and "dir/./file". If you don't want this, then use     
977         cleaner names.
978         The same applies to directories ending '/' and paths with '//'
979
980 Using --refresh
981 --refresh does not calculate a new sha1 file or bring the cache
982 up-to-date for mode/content changes. But what it _does_ do is to
983 "re-match" the stat information of a file with the cache, so that you
984 can refresh the cache for a file that hasn't been changed but where
985 the stat entry is out of date.
986
987 For example, you'd want to do this after doing a "git-read-tree", to link
988 up the stat cache details with the proper files.
989
990 Using --cacheinfo
991 --cacheinfo is used to register a file that is not in the current
992 working directory.  This is useful for minimum-checkout merging.
993
994 To pretend you have a file with mode and sha1 at path, say:
995
996  $ git-update-cache --cacheinfo mode sha1 path
997
998 To update and refresh only the files already checked out:
999
1000    git-checkout-cache -n -f -a && git-update-cache --ignore-missing --refresh
1001
1002
1003 ################################################################
1004 git-write-tree
1005         git-write-tree
1006
1007 Creates a tree object using the current cache.
1008
1009 The cache must be merged.
1010
1011 Conceptually, git-write-tree sync()s the current directory cache contents
1012 into a set of tree files.
1013 In order to have that match what is actually in your directory right
1014 now, you need to have done a "git-update-cache" phase before you did the
1015 "git-write-tree".
1016
1017
1018 ################################################################
1019
1020 Output format from git-diff-cache, git-diff-tree and git-diff-files.
1021
1022 These commands all compare two sets of things; what are
1023 compared are different:
1024
1025     git-diff-cache <tree-ish>
1026
1027         compares the <tree-ish> and the files on the filesystem.
1028
1029     git-diff-cache --cached <tree-ish>
1030
1031         compares the <tree-ish> and the cache.
1032
1033     git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]
1034
1035         compares the trees named by the two arguments.
1036
1037     git-diff-files [<pattern>...]
1038
1039         compares the cache and the files on the filesystem.
1040
1041 The following desription uses "old" and "new" to mean those
1042 compared entities.
1043
1044 For files in old but not in new (i.e. removed):
1045 -<mode> \t <type> \t <object> \t <path>
1046
1047 For files not in old but in new (i.e. added):
1048 +<mode> \t <type> \t <object> \t <path>
1049
1050 For files that differ:
1051 *<old-mode>-><new-mode> \t <type> \t <old-sha1>-><new-sha1> \t <path>
1052
1053 <new-sha1> is shown as all 0's if new is a file on the
1054 filesystem and it is out of sync with the cache.  Example:
1055
1056   *100644->100644 blob    5be4a4.......->000000.......      file.c
1057
1058 ################################################################
1059
1060 Generating patches
1061
1062 When git-diff-cache, git-diff-tree, or git-diff-files are run with a -p
1063 option, they do not produce the output described in "Output format from
1064 git-diff-cache, git-diff-tree and git-diff-files" section.  It instead
1065 produces a patch file.
1066
1067 The patch generation can be customized at two levels.  This
1068 customization also applies to git-diff-tree-helper.
1069
1070 1. When the environment variable GIT_EXTERNAL_DIFF is not set,
1071    these commands internally invoke diff like this:
1072
1073    diff -L a/<path> -L a/<path> -pu <old> <new>
1074
1075    For added files, /dev/null is used for <old>.  For removed
1076    files, /dev/null is used for <new>
1077
1078    The diff formatting options can be customized via the
1079    environment variable GIT_DIFF_OPTS.  For example, if you
1080    prefer context diff:
1081
1082    GIT_DIFF_OPTS=-c git-diff-cache -p $(cat .git/HEAD)
1083
1084
1085 2. When the environment variable GIT_EXTERNAL_DIFF is set, the
1086    program named by it is called, instead of the diff invocation
1087    described above.
1088
1089    For a path that is added, removed, or modified,
1090    GIT_EXTERNAL_DIFF is called with 7 parameters:
1091
1092      path old-file old-hex old-mode new-file new-hex new-mode
1093
1094    where
1095      <old|new>-file are files GIT_EXTERNAL_DIFF can use to read the
1096                     contents of <old|ne>,
1097      <old|new>-hex are the 40-hexdigit SHA1 hashes,
1098      <old|new>-mode are the octal representation of the file modes.
1099
1100    The file parameters can point at the user's working file (e.g. new-file
1101    in git-diff-files), /dev/null (e.g. old-file when a new file is added),
1102    or a temporary file (e.g. old-file in the cache).  GIT_EXTERNAL_DIFF
1103    should not worry about unlinking the temporary file --- it is removed
1104    when GIT_EXTERNAL_DIFF exits.
1105
1106    For a path that is unmerged, GIT_EXTERNAL_DIFF is called with
1107    1 parameter, path.
1108
1109 ################################################################
1110
1111 Terminology: - see README for description
1112 Each line contains terms used interchangeably
1113
1114 object database, .git directory
1115 directory cache, index
1116 id, sha1, sha1-id, sha1 hash
1117 type, tag
1118 blob, blob object
1119 tree, tree object
1120 commit, commit object
1121 parent
1122 root object
1123 changeset
1124
1125
1126 git Environment Variables
1127 AUTHOR_NAME
1128 AUTHOR_EMAIL
1129 AUTHOR_DATE
1130 COMMIT_AUTHOR_NAME
1131 COMMIT_AUTHOR_EMAIL
1132 GIT_DIFF_OPTS
1133 GIT_EXTERNAL_DIFF
1134 GIT_INDEX_FILE
1135 SHA1_FILE_DIRECTORY