1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\r
6 <meta name="generator" content="AsciiDoc 7.0.2" />
\r
7 <style type="text/css">
\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
\r
11 border: 1px solid red;
\r
16 margin: 1em 5% 1em 5%;
\r
20 a:visited { color: fuchsia; }
\r
34 h1, h2, h3, h4, h5, h6 {
\r
36 font-family: sans-serif;
\r
38 margin-bottom: 0.5em;
\r
43 border-bottom: 2px solid silver;
\r
46 border-bottom: 2px solid silver;
\r
56 border: 1px solid silver;
\r
61 margin-bottom: 0.5em;
\r
71 font-family: sans-serif;
\r
78 font-family: sans-serif;
\r
82 font-family: sans-serif;
\r
84 border-top: 2px solid silver;
\r
90 padding-bottom: 0.5em;
\r
94 padding-bottom: 0.5em;
\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
100 div.admonitionblock {
\r
103 margin-bottom: 1.5em;
\r
105 div.admonitionblock {
\r
107 margin-bottom: 2.5em;
\r
110 div.content { /* Block element content. */
\r
114 /* Block element titles. */
\r
115 div.title, caption.title {
\r
116 font-family: sans-serif;
\r
120 margin-bottom: 0.5em;
\r
126 td div.title:first-child {
\r
129 div.content div.title:first-child {
\r
132 div.content + div.title {
\r
136 div.sidebarblock > div.content {
\r
137 background: #ffffee;
\r
138 border: 1px solid silver;
\r
142 div.listingblock > div.content {
\r
143 border: 1px solid silver;
\r
144 background: #f4f4f4;
\r
148 div.quoteblock > div.content {
\r
149 padding-left: 2.0em;
\r
151 div.quoteblock .attribution {
\r
155 div.admonitionblock .icon {
\r
156 vertical-align: top;
\r
159 text-decoration: underline;
\r
161 padding-right: 0.5em;
\r
163 div.admonitionblock td.content {
\r
164 padding-left: 0.5em;
\r
165 border-left: 2px solid silver;
\r
168 div.exampleblock > div.content {
\r
169 border-left: 2px solid silver;
\r
173 div.verseblock div.content {
\r
177 div.imageblock div.content { padding-left: 0; }
\r
178 div.imageblock img { border: 1px solid silver; }
\r
179 span.image img { border-style: none; }
\r
183 margin-bottom: 0.8em;
\r
188 font-style: italic;
\r
190 dd > *:first-child {
\r
195 list-style-position: outside;
\r
198 list-style-type: lower-alpha;
\r
201 div.tableblock > table {
\r
202 border-color: #527bbd;
\r
206 font-family: sans-serif;
\r
215 margin-bottom: 0.8em;
\r
218 vertical-align: top;
\r
219 font-style: italic;
\r
220 padding-right: 0.8em;
\r
223 vertical-align: top;
\r
227 div#footer-badges { display: none; }
\r
229 include::./stylesheets/xhtml11-manpage.css[]
\r
230 /* Workarounds for IE6's broken and incomplete CSS2. */
\r
232 div.sidebar-content {
\r
233 background: #ffffee;
\r
234 border: 1px solid silver;
\r
237 div.sidebar-title, div.image-title {
\r
238 font-family: sans-serif;
\r
241 margin-bottom: 0.5em;
\r
244 div.listingblock div.content {
\r
245 border: 1px solid silver;
\r
246 background: #f4f4f4;
\r
250 div.quoteblock-content {
\r
251 padding-left: 2.0em;
\r
254 div.exampleblock-content {
\r
255 border-left: 2px solid silver;
\r
256 padding-left: 0.5em;
\r
259 <title>git(7)</title>
\r
267 <div class="sectionbody">
\r
269 the stupid content tracker
\r
274 <div class="sectionbody">
\r
275 <p><em>git</em> [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ARGS]</p>
\r
277 <h2>DESCRIPTION</h2>
\r
278 <div class="sectionbody">
\r
279 <p>Git is a fast, scalable, distributed revision control system with an
\r
280 unusually rich command set that provides both high-level operations
\r
281 and full access to internals.</p>
\r
282 <p>See this <a href="tutorial.html">tutorial</a> to get started, then see
\r
283 <a href="everyday.html">Everyday Git</a> for a useful minimum set of commands, and
\r
284 "man git-commandname" for documentation of each command. CVS users may
\r
285 also want to read <a href="cvs-migration.html">CVS migration</a>.</p>
\r
288 <div class="sectionbody">
\r
295 Prints the git suite version that the <em>git</em> program came from.
\r
303 Prints the synopsis and a list of the most commonly used
\r
304 commands. If a git command is named this option will bring up
\r
305 the man-page for that command. If the option <em>--all</em> or <em>-a</em> is
\r
306 given then all available commands are printed.
\r
314 Path to wherever your core git programs are installed.
\r
315 This can also be controlled by setting the GIT_EXEC_PATH
\r
316 environment variable. If no path is given <em>git</em> will print
\r
317 the current setting and then exit.
\r
322 <h2>FURTHER DOCUMENTATION</h2>
\r
323 <div class="sectionbody">
\r
324 <p>See the references above to get started using git. The following is
\r
325 probably more detail than necessary for a first-time user.</p>
\r
326 <p>The <a href="#Discussion">Discussion</a> section below and the
\r
327 <a href="core-tutorial.html">Core tutorial</a> both provide introductions to the
\r
328 underlying git architecture.</p>
\r
329 <p>See also the <a href="howto-index.html">howto</a> documents for some useful
\r
332 <h2>GIT COMMANDS</h2>
\r
333 <div class="sectionbody">
\r
334 <p>We divide git into high level ("porcelain") commands and low level
\r
335 ("plumbing") commands.</p>
\r
337 <h2>Low-level commands (plumbing)</h2>
\r
338 <div class="sectionbody">
\r
339 <p>Although git includes its
\r
340 own porcelain layer, its low-level commands are sufficient to support
\r
341 development of alternative porcelains. Developers of such porcelains
\r
342 might start by reading about <a href="git-update-index.html">git-update-index(1)</a> and
\r
343 <a href="git-read-tree.html">git-read-tree(1)</a>.</p>
\r
344 <p>We divide the low-level commands into commands that manipulate objects (in
\r
345 the repository, index, and working tree), commands that interrogate and
\r
346 compare objects, and commands that move objects and references between
\r
348 <h3>Manipulation commands</h3>
\r
351 <a href="git-apply.html">git-apply(1)</a>
\r
355 Reads a "diff -up1" or git generated patch file and
\r
356 applies it to the working tree.
\r
360 <a href="git-checkout-index.html">git-checkout-index(1)</a>
\r
364 Copy files from the index to the working tree.
\r
368 <a href="git-commit-tree.html">git-commit-tree(1)</a>
\r
372 Creates a new commit object.
\r
376 <a href="git-hash-object.html">git-hash-object(1)</a>
\r
380 Computes the object ID from a file.
\r
384 <a href="git-index-pack.html">git-index-pack(1)</a>
\r
388 Build pack idx file for an existing packed archive.
\r
392 <a href="git-init-db.html">git-init-db(1)</a>
\r
396 Creates an empty git object database, or reinitialize an
\r
401 <a href="git-merge-index.html">git-merge-index(1)</a>
\r
405 Runs a merge for files needing merging.
\r
409 <a href="git-mktag.html">git-mktag(1)</a>
\r
413 Creates a tag object.
\r
417 <a href="git-pack-objects.html">git-pack-objects(1)</a>
\r
421 Creates a packed archive of objects.
\r
425 <a href="git-prune-packed.html">git-prune-packed(1)</a>
\r
429 Remove extra objects that are already in pack files.
\r
433 <a href="git-read-tree.html">git-read-tree(1)</a>
\r
437 Reads tree information into the index.
\r
441 <a href="git-repo-config.html">git-repo-config(1)</a>
\r
445 Get and set options in .git/config.
\r
449 <a href="git-unpack-objects.html">git-unpack-objects(1)</a>
\r
453 Unpacks objects out of a packed archive.
\r
457 <a href="git-update-index.html">git-update-index(1)</a>
\r
461 Registers files in the working tree to the index.
\r
465 <a href="git-write-tree.html">git-write-tree(1)</a>
\r
469 Creates a tree from the index.
\r
473 <h3>Interrogation commands</h3>
\r
476 <a href="git-cat-file.html">git-cat-file(1)</a>
\r
480 Provide content or type/size information for repository objects.
\r
484 <a href="git-describe.html">git-describe(1)</a>
\r
488 Show the most recent tag that is reachable from a commit.
\r
492 <a href="git-diff-index.html">git-diff-index(1)</a>
\r
496 Compares content and mode of blobs between the index and repository.
\r
500 <a href="git-diff-files.html">git-diff-files(1)</a>
\r
504 Compares files in the working tree and the index.
\r
508 <a href="git-diff-stages.html">git-diff-stages(1)</a>
\r
512 Compares two "merge stages" in the index.
\r
516 <a href="git-diff-tree.html">git-diff-tree(1)</a>
\r
520 Compares the content and mode of blobs found via two tree objects.
\r
524 <a href="git-fsck-objects.html">git-fsck-objects(1)</a>
\r
528 Verifies the connectivity and validity of the objects in the database.
\r
532 <a href="git-ls-files.html">git-ls-files(1)</a>
\r
536 Information about files in the index and the working tree.
\r
540 <a href="git-ls-tree.html">git-ls-tree(1)</a>
\r
544 Displays a tree object in human readable form.
\r
548 <a href="git-merge-base.html">git-merge-base(1)</a>
\r
552 Finds as good common ancestors as possible for a merge.
\r
556 <a href="git-name-rev.html">git-name-rev(1)</a>
\r
560 Find symbolic names for given revs.
\r
564 <a href="git-pack-redundant.html">git-pack-redundant(1)</a>
\r
568 Find redundant pack files.
\r
572 <a href="git-rev-list.html">git-rev-list(1)</a>
\r
576 Lists commit objects in reverse chronological order.
\r
580 <a href="git-show-index.html">git-show-index(1)</a>
\r
584 Displays contents of a pack idx file.
\r
588 <a href="git-tar-tree.html">git-tar-tree(1)</a>
\r
592 Creates a tar archive of the files in the named tree object.
\r
596 <a href="git-unpack-file.html">git-unpack-file(1)</a>
\r
600 Creates a temporary file with a blob's contents.
\r
604 <a href="git-var.html">git-var(1)</a>
\r
608 Displays a git logical variable.
\r
612 <a href="git-verify-pack.html">git-verify-pack(1)</a>
\r
616 Validates packed git archive files.
\r
620 <p>In general, the interrogate commands do not touch the files in
\r
621 the working tree.</p>
\r
622 <h3>Synching repositories</h3>
\r
625 <a href="git-clone-pack.html">git-clone-pack(1)</a>
\r
629 Clones a repository into the current repository (engine
\r
630 for ssh and local transport).
\r
634 <a href="git-fetch-pack.html">git-fetch-pack(1)</a>
\r
638 Updates from a remote repository (engine for ssh and
\r
643 <a href="git-http-fetch.html">git-http-fetch(1)</a>
\r
647 Downloads a remote git repository via HTTP by walking
\r
652 <a href="git-local-fetch.html">git-local-fetch(1)</a>
\r
656 Duplicates another git repository on a local system by
\r
657 walking commit chain.
\r
661 <a href="git-peek-remote.html">git-peek-remote(1)</a>
\r
665 Lists references on a remote repository using
\r
666 upload-pack protocol (engine for ssh and local
\r
671 <a href="git-receive-pack.html">git-receive-pack(1)</a>
\r
675 Invoked by <em>git-send-pack</em> to receive what is pushed to it.
\r
679 <a href="git-send-pack.html">git-send-pack(1)</a>
\r
683 Pushes to a remote repository, intelligently.
\r
687 <a href="git-http-push.html">git-http-push(1)</a>
\r
691 Push missing objects using HTTP/DAV.
\r
695 <a href="git-shell.html">git-shell(1)</a>
\r
699 Restricted shell for GIT-only SSH access.
\r
703 <a href="git-ssh-fetch.html">git-ssh-fetch(1)</a>
\r
707 Pulls from a remote repository over ssh connection by
\r
708 walking commit chain.
\r
712 <a href="git-ssh-upload.html">git-ssh-upload(1)</a>
\r
716 Helper "server-side" program used by git-ssh-fetch.
\r
720 <a href="git-update-server-info.html">git-update-server-info(1)</a>
\r
724 Updates auxiliary information on a dumb server to help
\r
725 clients discover references and packs on it.
\r
729 <a href="git-upload-pack.html">git-upload-pack(1)</a>
\r
733 Invoked by <em>git-clone-pack</em> and <em>git-fetch-pack</em> to push
\r
734 what are asked for.
\r
739 <h2>High-level commands (porcelain)</h2>
\r
740 <div class="sectionbody">
\r
741 <p>We separate the porcelain commands into the main commands and some
\r
742 ancillary user utilities.</p>
\r
743 <h3>Main porcelain commands</h3>
\r
746 <a href="git-add.html">git-add(1)</a>
\r
750 Add paths to the index.
\r
754 <a href="git-am.html">git-am(1)</a>
\r
758 Apply patches from a mailbox, but cooler.
\r
762 <a href="git-applymbox.html">git-applymbox(1)</a>
\r
766 Apply patches from a mailbox, original version by Linus.
\r
770 <a href="git-bisect.html">git-bisect(1)</a>
\r
774 Find the change that introduced a bug by binary search.
\r
778 <a href="git-branch.html">git-branch(1)</a>
\r
782 Create and Show branches.
\r
786 <a href="git-checkout.html">git-checkout(1)</a>
\r
790 Checkout and switch to a branch.
\r
794 <a href="git-cherry-pick.html">git-cherry-pick(1)</a>
\r
798 Cherry-pick the effect of an existing commit.
\r
802 <a href="git-clone.html">git-clone(1)</a>
\r
806 Clones a repository into a new directory.
\r
810 <a href="git-commit.html">git-commit(1)</a>
\r
814 Record changes to the repository.
\r
818 <a href="git-diff.html">git-diff(1)</a>
\r
822 Show changes between commits, commit and working tree, etc.
\r
826 <a href="git-fetch.html">git-fetch(1)</a>
\r
830 Download from a remote repository via various protocols.
\r
834 <a href="git-format-patch.html">git-format-patch(1)</a>
\r
838 Prepare patches for e-mail submission.
\r
842 <a href="git-grep.html">git-grep(1)</a>
\r
846 Print lines matching a pattern.
\r
850 <a href="git-log.html">git-log(1)</a>
\r
858 <a href="git-ls-remote.html">git-ls-remote(1)</a>
\r
862 Shows references in a remote or local repository.
\r
866 <a href="git-merge.html">git-merge(1)</a>
\r
870 Grand unified merge driver.
\r
874 <a href="git-mv.html">git-mv(1)</a>
\r
878 Move or rename a file, a directory, or a symlink.
\r
882 <a href="git-pull.html">git-pull(1)</a>
\r
886 Fetch from and merge with a remote repository.
\r
890 <a href="git-push.html">git-push(1)</a>
\r
894 Update remote refs along with associated objects.
\r
898 <a href="git-rebase.html">git-rebase(1)</a>
\r
902 Rebase local commits to the updated upstream head.
\r
906 <a href="git-repack.html">git-repack(1)</a>
\r
910 Pack unpacked objects in a repository.
\r
914 <a href="git-rerere.html">git-rerere(1)</a>
\r
918 Reuse recorded resolution of conflicted merges.
\r
922 <a href="git-reset.html">git-reset(1)</a>
\r
926 Reset current HEAD to the specified state.
\r
930 <a href="git-resolve.html">git-resolve(1)</a>
\r
938 <a href="git-revert.html">git-revert(1)</a>
\r
942 Revert an existing commit.
\r
946 <a href="git-shortlog.html">git-shortlog(1)</a>
\r
950 Summarizes <em>git log</em> output.
\r
954 <a href="git-show.html">git-show(1)</a>
\r
958 Show one commit log and its diff.
\r
962 <a href="git-show-branch.html">git-show-branch(1)</a>
\r
966 Show branches and their commits.
\r
970 <a href="git-status.html">git-status(1)</a>
\r
974 Shows the working tree status.
\r
978 <a href="git-verify-tag.html">git-verify-tag(1)</a>
\r
982 Check the GPG signature of tag.
\r
986 <a href="git-whatchanged.html">git-whatchanged(1)</a>
\r
990 Shows commit logs and differences they introduce.
\r
994 <h3>Ancillary Commands</h3>
\r
995 <p>Manipulators:</p>
\r
998 <a href="git-applypatch.html">git-applypatch(1)</a>
\r
1002 Apply one patch extracted from an e-mail.
\r
1006 <a href="git-archimport.html">git-archimport(1)</a>
\r
1010 Import an arch repository into git.
\r
1014 <a href="git-convert-objects.html">git-convert-objects(1)</a>
\r
1018 Converts old-style git repository.
\r
1022 <a href="git-cvsimport.html">git-cvsimport(1)</a>
\r
1026 Salvage your data out of another SCM people love to hate.
\r
1030 <a href="git-cvsexportcommit.html">git-cvsexportcommit(1)</a>
\r
1034 Export a single commit to a CVS checkout.
\r
1038 <a href="git-lost-found.html">git-lost-found(1)</a>
\r
1042 Recover lost refs that luckily have not yet been pruned.
\r
1046 <a href="git-merge-one-file.html">git-merge-one-file(1)</a>
\r
1050 The standard helper program to use with <tt>git-merge-index</tt>.
\r
1054 <a href="git-prune.html">git-prune(1)</a>
\r
1058 Prunes all unreachable objects from the object database.
\r
1062 <a href="git-relink.html">git-relink(1)</a>
\r
1066 Hardlink common objects in local repositories.
\r
1070 <a href="git-svnimport.html">git-svnimport(1)</a>
\r
1074 Import a SVN repository into git.
\r
1078 <a href="git-sh-setup.html">git-sh-setup(1)</a>
\r
1082 Common git shell script setup code.
\r
1086 <a href="git-symbolic-ref.html">git-symbolic-ref(1)</a>
\r
1090 Read and modify symbolic refs.
\r
1094 <a href="git-tag.html">git-tag(1)</a>
\r
1098 An example script to create a tag object signed with GPG.
\r
1102 <a href="git-update-ref.html">git-update-ref(1)</a>
\r
1106 Update the object name stored in a ref safely.
\r
1110 <p>Interrogators:</p>
\r
1113 <a href="git-check-ref-format.html">git-check-ref-format(1)</a>
\r
1117 Make sure ref name is well formed.
\r
1121 <a href="git-cherry.html">git-cherry(1)</a>
\r
1125 Find commits not merged upstream.
\r
1129 <a href="git-count-objects.html">git-count-objects(1)</a>
\r
1133 Count unpacked number of objects and their disk consumption.
\r
1137 <a href="git-daemon.html">git-daemon(1)</a>
\r
1141 A really simple server for git repositories.
\r
1145 <a href="git-get-tar-commit-id.html">git-get-tar-commit-id(1)</a>
\r
1149 Extract commit ID from an archive created using git-tar-tree.
\r
1153 <a href="git-mailinfo.html">git-mailinfo(1)</a>
\r
1157 Extracts patch and authorship information from a single
\r
1158 e-mail message, optionally transliterating the commit
\r
1159 message into utf-8.
\r
1163 <a href="git-mailsplit.html">git-mailsplit(1)</a>
\r
1167 A stupid program to split UNIX mbox format mailbox into
\r
1168 individual pieces of e-mail.
\r
1172 <a href="git-patch-id.html">git-patch-id(1)</a>
\r
1176 Compute unique ID for a patch.
\r
1180 <a href="git-parse-remote.html">git-parse-remote(1)</a>
\r
1184 Routines to help parsing <tt>$GIT_DIR/remotes/</tt> files.
\r
1188 <a href="git-request-pull.html">git-request-pull(1)</a>
\r
1196 <a href="git-rev-parse.html">git-rev-parse(1)</a>
\r
1200 Pick out and massage parameters.
\r
1204 <a href="git-send-email.html">git-send-email(1)</a>
\r
1208 Send patch e-mails out of "format-patch --mbox" output.
\r
1212 <a href="git-symbolic-ref.html">git-symbolic-ref(1)</a>
\r
1216 Read and modify symbolic refs.
\r
1220 <a href="git-stripspace.html">git-stripspace(1)</a>
\r
1224 Filter out empty lines.
\r
1229 <h2>Commands not yet documented</h2>
\r
1230 <div class="sectionbody">
\r
1233 <a href="gitk.html">gitk(1)</a>
\r
1237 The gitk repository browser.
\r
1242 <h2>Configuration Mechanism</h2>
\r
1243 <div class="sectionbody">
\r
1244 <p>Starting from 0.99.9 (actually mid 0.99.8.GIT), <tt>.git/config</tt> file
\r
1245 is used to hold per-repository configuration options. It is a
\r
1246 simple text file modelled after <tt>.ini</tt> format familiar to some
\r
1247 people. Here is an example:</p>
\r
1248 <div class="listingblock">
\r
1249 <div class="content">
\r
1251 # A '#' or ';' character indicates a comment.
\r
1256 ; Don't trust file modes
\r
1261 name = "Junio C Hamano"
\r
1262 email = "junkio@twinsun.com"
\r
1265 <p>Various commands read from the configuration file and adjust
\r
1266 their operation accordingly.</p>
\r
1268 <h2>Identifier Terminology</h2>
\r
1269 <div class="sectionbody">
\r
1276 Indicates the object name for any type of object.
\r
1284 Indicates a blob object name.
\r
1292 Indicates a tree object name.
\r
1300 Indicates a commit object name.
\r
1308 Indicates a tree, commit or tag object name. A
\r
1309 command that takes a <tree-ish> argument ultimately wants to
\r
1310 operate on a <tree> object but automatically dereferences
\r
1311 <commit> and <tag> objects that point at a <tree>.
\r
1319 Indicates that an object type is required.
\r
1320 Currently one of: <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>, or <tt>tag</tt>.
\r
1328 Indicates a filename - almost always relative to the
\r
1329 root of the tree structure <tt>GIT_INDEX_FILE</tt> describes.
\r
1334 <h2>Symbolic Identifiers</h2>
\r
1335 <div class="sectionbody">
\r
1336 <p>Any git command accepting any <object> can also use the following
\r
1337 symbolic notation:</p>
\r
1344 indicates the head of the current branch (i.e. the
\r
1345 contents of <tt>$GIT_DIR/HEAD</tt>).
\r
1353 a valid tag <em>name</em>
\r
1354 (i.e. the contents of <tt>$GIT_DIR/refs/tags/<tag></tt>).
\r
1362 a valid head <em>name</em>
\r
1363 (i.e. the contents of <tt>$GIT_DIR/refs/heads/<head></tt>).
\r
1368 <h2>File/Directory Structure</h2>
\r
1369 <div class="sectionbody">
\r
1370 <p>Please see <a href="repository-layout.html">repository layout</a> document.</p>
\r
1371 <p>Read <a href="hooks.html">hooks</a> for more details about each hook.</p>
\r
1372 <p>Higher level SCMs may provide and manage additional information in the
\r
1373 <tt>$GIT_DIR</tt>.</p>
\r
1375 <h2>Terminology</h2>
\r
1376 <div class="sectionbody">
\r
1377 <p>Please see <a href="glossary.html">glossary</a> document.</p>
\r
1379 <h2>Environment Variables</h2>
\r
1380 <div class="sectionbody">
\r
1381 <p>Various git commands use the following environment variables:</p>
\r
1382 <h3>The git Repository</h3>
\r
1383 <p>These environment variables apply to <em>all</em> core git commands. Nb: it
\r
1384 is worth noting that they may be used/overridden by SCMS sitting above
\r
1385 git so take care if using Cogito etc.</p>
\r
1388 <em>GIT_INDEX_FILE</em>
\r
1392 This environment allows the specification of an alternate
\r
1393 index file. If not specified, the default of <tt>$GIT_DIR/index</tt>
\r
1398 <em>GIT_OBJECT_DIRECTORY</em>
\r
1402 If the object storage directory is specified via this
\r
1403 environment variable then the sha1 directories are created
\r
1404 underneath - otherwise the default <tt>$GIT_DIR/objects</tt>
\r
1405 directory is used.
\r
1409 <em>GIT_ALTERNATE_OBJECT_DIRECTORIES</em>
\r
1413 Due to the immutable nature of git objects, old objects can be
\r
1414 archived into shared, read-only directories. This variable
\r
1415 specifies a ":" separated list of git object directories which
\r
1416 can be used to search for git objects. New objects will not be
\r
1417 written to these directories.
\r
1425 If the <em>GIT_DIR</em> environment variable is set then it
\r
1426 specifies a path to use instead of the default <tt>.git</tt>
\r
1427 for the base of the repository.
\r
1431 <h3>git Commits</h3>
\r
1434 <em>GIT_AUTHOR_NAME</em>
\r
1437 <em>GIT_AUTHOR_EMAIL</em>
\r
1440 <em>GIT_AUTHOR_DATE</em>
\r
1443 <em>GIT_COMMITTER_NAME</em>
\r
1446 <em>GIT_COMMITTER_EMAIL</em>
\r
1450 see <a href="git-commit-tree.html">git-commit-tree(1)</a>
\r
1454 <h3>git Diffs</h3>
\r
1457 <em>GIT_DIFF_OPTS</em>
\r
1460 <em>GIT_EXTERNAL_DIFF</em>
\r
1464 see the "generating patches" section in :
\r
1465 <a href="git-diff-index.html">git-diff-index(1)</a>;
\r
1466 <a href="git-diff-files.html">git-diff-files(1)</a>;
\r
1467 <a href="git-diff-tree.html">git-diff-tree(1)</a>
\r
1472 <h2>Discussion<a id="Discussion"></a></h2>
\r
1473 <div class="sectionbody">
\r
1474 <p>"git" can mean anything, depending on your mood.</p>
\r
1478 random three-letter combination that is pronounceable, and not
\r
1479 actually used by any common UNIX command. The fact that it is a
\r
1480 mispronunciation of "get" may or may not be relevant.
\r
1485 stupid. contemptible and despicable. simple. Take your pick from the
\r
1486 dictionary of slang.
\r
1491 "global information tracker": you're in a good mood, and it actually
\r
1492 works for you. Angels sing, and a light suddenly fills the room.
\r
1497 "goddamn idiotic truckload of sh*t": when it breaks
\r
1501 <p>This is a stupid (but extremely fast) directory content manager. It
\r
1502 doesn't do a whole lot, but what it <em>does</em> do is track directory
\r
1503 contents efficiently.</p>
\r
1504 <p>There are two object abstractions: the "object database", and the
\r
1505 "current directory cache" aka "index".</p>
\r
1506 <h3>The Object Database</h3>
\r
1507 <p>The object database is literally just a content-addressable collection
\r
1508 of objects. All objects are named by their content, which is
\r
1509 approximated by the SHA1 hash of the object itself. Objects may refer
\r
1510 to other objects (by referencing their SHA1 hash), and so you can
\r
1511 build up a hierarchy of objects.</p>
\r
1512 <p>All objects have a statically determined "type" aka "tag", which is
\r
1513 determined at object creation time, and which identifies the format of
\r
1514 the object (i.e. how it is used, and how it can refer to other
\r
1515 objects). There are currently four different object types: "blob",
\r
1516 "tree", "commit" and "tag".</p>
\r
1517 <p>A "blob" object cannot refer to any other object, and is, like the type
\r
1518 implies, a pure storage object containing some user data. It is used to
\r
1519 actually store the file data, i.e. a blob object is associated with some
\r
1520 particular version of some file.</p>
\r
1521 <p>A "tree" object is an object that ties one or more "blob" objects into a
\r
1522 directory structure. In addition, a tree object can refer to other tree
\r
1523 objects, thus creating a directory hierarchy.</p>
\r
1524 <p>A "commit" object ties such directory hierarchies together into
\r
1525 a DAG of revisions - each "commit" is associated with exactly one tree
\r
1526 (the directory hierarchy at the time of the commit). In addition, a
\r
1527 "commit" refers to one or more "parent" commit objects that describe the
\r
1528 history of how we arrived at that directory hierarchy.</p>
\r
1529 <p>As a special case, a commit object with no parents is called the "root"
\r
1530 object, and is the point of an initial project commit. Each project
\r
1531 must have at least one root, and while you can tie several different
\r
1532 root objects together into one project by creating a commit object which
\r
1533 has two or more separate roots as its ultimate parents, that's probably
\r
1534 just going to confuse people. So aim for the notion of "one root object
\r
1535 per project", even if git itself does not enforce that.</p>
\r
1536 <p>A "tag" object symbolically identifies and can be used to sign other
\r
1537 objects. It contains the identifier and type of another object, a
\r
1538 symbolic name (of course!) and, optionally, a signature.</p>
\r
1539 <p>Regardless of object type, all objects share the following
\r
1540 characteristics: they are all deflated with zlib, and have a header
\r
1541 that not only specifies their type, but also provides size information
\r
1542 about the data in the object. It's worth noting that the SHA1 hash
\r
1543 that is used to name the object is the hash of the original data
\r
1544 plus this header, so <tt>sha1sum</tt> <em>file</em> does not match the object name
\r
1545 for <em>file</em>.
\r
1546 (Historical note: in the dawn of the age of git the hash
\r
1547 was the sha1 of the <em>compressed</em> object.)</p>
\r
1548 <p>As a result, the general consistency of an object can always be tested
\r
1549 independently of the contents or the type of the object: all objects can
\r
1550 be validated by verifying that (a) their hashes match the content of the
\r
1551 file and (b) the object successfully inflates to a stream of bytes that
\r
1552 forms a sequence of <ascii type without space> + <space> + <ascii decimal
\r
1553 size> + <byte\0> + <binary object data>.</p>
\r
1554 <p>The structured objects can further have their structure and
\r
1555 connectivity to other objects verified. This is generally done with
\r
1556 the <tt>git-fsck-objects</tt> program, which generates a full dependency graph
\r
1557 of all objects, and verifies their internal consistency (in addition
\r
1558 to just verifying their superficial consistency through the hash).</p>
\r
1559 <p>The object types in some more detail:</p>
\r
1560 <h3>Blob Object</h3>
\r
1561 <p>A "blob" object is nothing but a binary blob of data, and doesn't
\r
1562 refer to anything else. There is no signature or any other
\r
1563 verification of the data, so while the object is consistent (it <em>is</em>
\r
1564 indexed by its sha1 hash, so the data itself is certainly correct), it
\r
1565 has absolutely no other attributes. No name associations, no
\r
1566 permissions. It is purely a blob of data (i.e. normally "file
\r
1568 <p>In particular, since the blob is entirely defined by its data, if two
\r
1569 files in a directory tree (or in multiple different versions of the
\r
1570 repository) have the same contents, they will share the same blob
\r
1571 object. The object is totally independent of its location in the
\r
1572 directory tree, and renaming a file does not change the object that
\r
1573 file is associated with in any way.</p>
\r
1574 <p>A blob is typically created when <a href="git-update-index.html">git-update-index(1)</a>
\r
1575 is run, and its data can be accessed by <a href="git-cat-file.html">git-cat-file(1)</a>.</p>
\r
1576 <h3>Tree Object</h3>
\r
1577 <p>The next hierarchical object type is the "tree" object. A tree object
\r
1578 is a list of mode/name/blob data, sorted by name. Alternatively, the
\r
1579 mode data may specify a directory mode, in which case instead of
\r
1580 naming a blob, that name is associated with another TREE object.</p>
\r
1581 <p>Like the "blob" object, a tree object is uniquely determined by the
\r
1582 set contents, and so two separate but identical trees will always
\r
1583 share the exact same object. This is true at all levels, i.e. it's
\r
1584 true for a "leaf" tree (which does not refer to any other trees, only
\r
1585 blobs) as well as for a whole subdirectory.</p>
\r
1586 <p>For that reason a "tree" object is just a pure data abstraction: it
\r
1587 has no history, no signatures, no verification of validity, except
\r
1588 that since the contents are again protected by the hash itself, we can
\r
1589 trust that the tree is immutable and its contents never change.</p>
\r
1590 <p>So you can trust the contents of a tree to be valid, the same way you
\r
1591 can trust the contents of a blob, but you don't know where those
\r
1592 contents <em>came</em> from.</p>
\r
1593 <p>Side note on trees: since a "tree" object is a sorted list of
\r
1594 "filename+content", you can create a diff between two trees without
\r
1595 actually having to unpack two trees. Just ignore all common parts,
\r
1596 and your diff will look right. In other words, you can effectively
\r
1597 (and efficiently) tell the difference between any two random trees by
\r
1598 O(n) where "n" is the size of the difference, rather than the size of
\r
1600 <p>Side note 2 on trees: since the name of a "blob" depends entirely and
\r
1601 exclusively on its contents (i.e. there are no names or permissions
\r
1602 involved), you can see trivial renames or permission changes by
\r
1603 noticing that the blob stayed the same. However, renames with data
\r
1604 changes need a smarter "diff" implementation.</p>
\r
1605 <p>A tree is created with <a href="git-write-tree.html">git-write-tree(1)</a> and
\r
1606 its data can be accessed by <a href="git-ls-tree.html">git-ls-tree(1)</a>.
\r
1607 Two trees can be compared with <a href="git-diff-tree.html">git-diff-tree(1)</a>.</p>
\r
1608 <h3>Commit Object</h3>
\r
1609 <p>The "commit" object is an object that introduces the notion of
\r
1610 history into the picture. In contrast to the other objects, it
\r
1611 doesn't just describe the physical state of a tree, it describes how
\r
1612 we got there, and why.</p>
\r
1613 <p>A "commit" is defined by the tree-object that it results in, the
\r
1614 parent commits (zero, one or more) that led up to that point, and a
\r
1615 comment on what happened. Again, a commit is not trusted per se:
\r
1616 the contents are well-defined and "safe" due to the cryptographically
\r
1617 strong signatures at all levels, but there is no reason to believe
\r
1618 that the tree is "good" or that the merge information makes sense.
\r
1619 The parents do not have to actually have any relationship with the
\r
1620 result, for example.</p>
\r
1621 <p>Note on commits: unlike real SCM's, commits do not contain
\r
1622 rename information or file mode change information. All of that is
\r
1623 implicit in the trees involved (the result tree, and the result trees
\r
1624 of the parents), and describing that makes no sense in this idiotic
\r
1626 <p>A commit is created with <a href="git-commit-tree.html">git-commit-tree(1)</a> and
\r
1627 its data can be accessed by <a href="git-cat-file.html">git-cat-file(1)</a>.</p>
\r
1629 <p>An aside on the notion of "trust". Trust is really outside the scope
\r
1630 of "git", but it's worth noting a few things. First off, since
\r
1631 everything is hashed with SHA1, you <em>can</em> trust that an object is
\r
1632 intact and has not been messed with by external sources. So the name
\r
1633 of an object uniquely identifies a known state - just not a state that
\r
1634 you may want to trust.</p>
\r
1635 <p>Furthermore, since the SHA1 signature of a commit refers to the
\r
1636 SHA1 signatures of the tree it is associated with and the signatures
\r
1637 of the parent, a single named commit specifies uniquely a whole set
\r
1638 of history, with full contents. You can't later fake any step of the
\r
1639 way once you have the name of a commit.</p>
\r
1640 <p>So to introduce some real trust in the system, the only thing you need
\r
1641 to do is to digitally sign just <em>one</em> special note, which includes the
\r
1642 name of a top-level commit. Your digital signature shows others
\r
1643 that you trust that commit, and the immutability of the history of
\r
1644 commits tells others that they can trust the whole history.</p>
\r
1645 <p>In other words, you can easily validate a whole archive by just
\r
1646 sending out a single email that tells the people the name (SHA1 hash)
\r
1647 of the top commit, and digitally sign that email using something
\r
1649 <p>To assist in this, git also provides the tag object…</p>
\r
1650 <h3>Tag Object</h3>
\r
1651 <p>Git provides the "tag" object to simplify creating, managing and
\r
1652 exchanging symbolic and signed tokens. The "tag" object at its
\r
1653 simplest simply symbolically identifies another object by containing
\r
1654 the sha1, type and symbolic name.</p>
\r
1655 <p>However it can optionally contain additional signature information
\r
1656 (which git doesn't care about as long as there's less than 8k of
\r
1657 it). This can then be verified externally to git.</p>
\r
1658 <p>Note that despite the tag features, "git" itself only handles content
\r
1659 integrity; the trust framework (and signature provision and
\r
1660 verification) has to come from outside.</p>
\r
1661 <p>A tag is created with <a href="git-mktag.html">git-mktag(1)</a>,
\r
1662 its data can be accessed by <a href="git-cat-file.html">git-cat-file(1)</a>,
\r
1663 and the signature can be verified by
\r
1664 <a href="git-verify-tag.html">git-verify-tag(1)</a>.</p>
\r
1666 <h2>The "index" aka "Current Directory Cache"</h2>
\r
1667 <div class="sectionbody">
\r
1668 <p>The index is a simple binary file, which contains an efficient
\r
1669 representation of a virtual directory content at some random time. It
\r
1670 does so by a simple array that associates a set of names, dates,
\r
1671 permissions and content (aka "blob") objects together. The cache is
\r
1672 always kept ordered by name, and names are unique (with a few very
\r
1673 specific rules) at any point in time, but the cache has no long-term
\r
1674 meaning, and can be partially updated at any time.</p>
\r
1675 <p>In particular, the index certainly does not need to be consistent with
\r
1676 the current directory contents (in fact, most operations will depend on
\r
1677 different ways to make the index <em>not</em> be consistent with the directory
\r
1678 hierarchy), but it has three very important attributes:</p>
\r
1679 <p><em>(a) it can re-generate the full state it caches (not just the
\r
1680 directory structure: it contains pointers to the "blob" objects so
\r
1681 that it can regenerate the data too)</em></p>
\r
1682 <p>As a special case, there is a clear and unambiguous one-way mapping
\r
1683 from a current directory cache to a "tree object", which can be
\r
1684 efficiently created from just the current directory cache without
\r
1685 actually looking at any other data. So a directory cache at any one
\r
1686 time uniquely specifies one and only one "tree" object (but has
\r
1687 additional data to make it easy to match up that tree object with what
\r
1688 has happened in the directory)</p>
\r
1689 <p><em>(b) it has efficient methods for finding inconsistencies between that
\r
1690 cached state ("tree object waiting to be instantiated") and the
\r
1691 current state.</em></p>
\r
1692 <p><em>(c) it can additionally efficiently represent information about merge
\r
1693 conflicts between different tree objects, allowing each pathname to be
\r
1694 associated with sufficient information about the trees involved that
\r
1695 you can create a three-way merge between them.</em></p>
\r
1696 <p>Those are the three ONLY things that the directory cache does. It's a
\r
1697 cache, and the normal operation is to re-generate it completely from a
\r
1698 known tree object, or update/compare it with a live tree that is being
\r
1699 developed. If you blow the directory cache away entirely, you generally
\r
1700 haven't lost any information as long as you have the name of the tree
\r
1701 that it described.</p>
\r
1702 <p>At the same time, the index is at the same time also the
\r
1703 staging area for creating new trees, and creating a new tree always
\r
1704 involves a controlled modification of the index file. In particular,
\r
1705 the index file can have the representation of an intermediate tree that
\r
1706 has not yet been instantiated. So the index can be thought of as a
\r
1707 write-back cache, which can contain dirty information that has not yet
\r
1708 been written back to the backing store.</p>
\r
1710 <h2>The Workflow</h2>
\r
1711 <div class="sectionbody">
\r
1712 <p>Generally, all "git" operations work on the index file. Some operations
\r
1713 work <strong>purely</strong> on the index file (showing the current state of the
\r
1714 index), but most operations move data to and from the index file. Either
\r
1715 from the database or from the working directory. Thus there are four
\r
1716 main combinations:</p>
\r
1717 <h3>1) working directory -> index</h3>
\r
1718 <p>You update the index with information from the working directory with
\r
1719 the <a href="git-update-index.html">git-update-index(1)</a> command. You
\r
1720 generally update the index information by just specifying the filename
\r
1721 you want to update, like so:</p>
\r
1722 <div class="literalblock">
\r
1723 <div class="content">
\r
1724 <pre><tt>git-update-index filename</tt></pre>
\r
1726 <p>but to avoid common mistakes with filename globbing etc, the command
\r
1727 will not normally add totally new entries or remove old entries,
\r
1728 i.e. it will normally just update existing cache entries.</p>
\r
1729 <p>To tell git that yes, you really do realize that certain files no
\r
1730 longer exist, or that new files should be added, you
\r
1731 should use the <tt>--remove</tt> and <tt>--add</tt> flags respectively.</p>
\r
1732 <p>NOTE! A <tt>--remove</tt> flag does <em>not</em> mean that subsequent filenames will
\r
1733 necessarily be removed: if the files still exist in your directory
\r
1734 structure, the index will be updated with their new status, not
\r
1735 removed. The only thing <tt>--remove</tt> means is that update-cache will be
\r
1736 considering a removed file to be a valid thing, and if the file really
\r
1737 does not exist any more, it will update the index accordingly.</p>
\r
1738 <p>As a special case, you can also do <tt>git-update-index --refresh</tt>, which
\r
1739 will refresh the "stat" information of each index to match the current
\r
1740 stat information. It will <em>not</em> update the object status itself, and
\r
1741 it will only update the fields that are used to quickly test whether
\r
1742 an object still matches its old backing store object.</p>
\r
1743 <h3>2) index -> object database</h3>
\r
1744 <p>You write your current index file to a "tree" object with the program</p>
\r
1745 <div class="literalblock">
\r
1746 <div class="content">
\r
1747 <pre><tt>git-write-tree</tt></pre>
\r
1749 <p>that doesn't come with any options - it will just write out the
\r
1750 current index into the set of tree objects that describe that state,
\r
1751 and it will return the name of the resulting top-level tree. You can
\r
1752 use that tree to re-generate the index at any time by going in the
\r
1753 other direction:</p>
\r
1754 <h3>3) object database -> index</h3>
\r
1755 <p>You read a "tree" file from the object database, and use that to
\r
1756 populate (and overwrite - don't do this if your index contains any
\r
1757 unsaved state that you might want to restore later!) your current
\r
1758 index. Normal operation is just</p>
\r
1759 <div class="literalblock">
\r
1760 <div class="content">
\r
1761 <pre><tt>git-read-tree <sha1 of tree></tt></pre>
\r
1763 <p>and your index file will now be equivalent to the tree that you saved
\r
1764 earlier. However, that is only your <em>index</em> file: your working
\r
1765 directory contents have not been modified.</p>
\r
1766 <h3>4) index -> working directory</h3>
\r
1767 <p>You update your working directory from the index by "checking out"
\r
1768 files. This is not a very common operation, since normally you'd just
\r
1769 keep your files updated, and rather than write to your working
\r
1770 directory, you'd tell the index files about the changes in your
\r
1771 working directory (i.e. <tt>git-update-index</tt>).</p>
\r
1772 <p>However, if you decide to jump to a new version, or check out somebody
\r
1773 else's version, or just restore a previous tree, you'd populate your
\r
1774 index file with read-tree, and then you need to check out the result
\r
1776 <div class="literalblock">
\r
1777 <div class="content">
\r
1778 <pre><tt>git-checkout-index filename</tt></pre>
\r
1780 <p>or, if you want to check out all of the index, use <tt>-a</tt>.</p>
\r
1781 <p>NOTE! git-checkout-index normally refuses to overwrite old files, so
\r
1782 if you have an old version of the tree already checked out, you will
\r
1783 need to use the "-f" flag (<em>before</em> the "-a" flag or the filename) to
\r
1784 <em>force</em> the checkout.</p>
\r
1785 <p>Finally, there are a few odds and ends which are not purely moving
\r
1786 from one representation to the other:</p>
\r
1787 <h3>5) Tying it all together</h3>
\r
1788 <p>To commit a tree you have instantiated with "git-write-tree", you'd
\r
1789 create a "commit" object that refers to that tree and the history
\r
1790 behind it - most notably the "parent" commits that preceded it in
\r
1792 <p>Normally a "commit" has one parent: the previous state of the tree
\r
1793 before a certain change was made. However, sometimes it can have two
\r
1794 or more parent commits, in which case we call it a "merge", due to the
\r
1795 fact that such a commit brings together ("merges") two or more
\r
1796 previous states represented by other commits.</p>
\r
1797 <p>In other words, while a "tree" represents a particular directory state
\r
1798 of a working directory, a "commit" represents that state in "time",
\r
1799 and explains how we got there.</p>
\r
1800 <p>You create a commit object by giving it the tree that describes the
\r
1801 state at the time of the commit, and a list of parents:</p>
\r
1802 <div class="literalblock">
\r
1803 <div class="content">
\r
1804 <pre><tt>git-commit-tree <tree> -p <parent> [-p <parent2> ..]</tt></pre>
\r
1806 <p>and then giving the reason for the commit on stdin (either through
\r
1807 redirection from a pipe or file, or by just typing it at the tty).</p>
\r
1808 <p>git-commit-tree will return the name of the object that represents
\r
1809 that commit, and you should save it away for later use. Normally,
\r
1810 you'd commit a new <tt>HEAD</tt> state, and while git doesn't care where you
\r
1811 save the note about that state, in practice we tend to just write the
\r
1812 result to the file pointed at by <tt>.git/HEAD</tt>, so that we can always see
\r
1813 what the last committed state was.</p>
\r
1814 <p>Here is an ASCII art by Jon Loeliger that illustrates how
\r
1815 various pieces fit together.</p>
\r
1816 <div class="listingblock">
\r
1817 <div class="content">
\r
1843 checkout-index -u | | checkout-index
\r
1852 <h3>6) Examining the data</h3>
\r
1853 <p>You can examine the data represented in the object database and the
\r
1854 index with various helper tools. For every object, you can use
\r
1855 <a href="git-cat-file.html">git-cat-file(1)</a> to examine details about the
\r
1857 <div class="literalblock">
\r
1858 <div class="content">
\r
1859 <pre><tt>git-cat-file -t <objectname></tt></pre>
\r
1861 <p>shows the type of the object, and once you have the type (which is
\r
1862 usually implicit in where you find the object), you can use</p>
\r
1863 <div class="literalblock">
\r
1864 <div class="content">
\r
1865 <pre><tt>git-cat-file blob|tree|commit|tag <objectname></tt></pre>
\r
1867 <p>to show its contents. NOTE! Trees have binary content, and as a result
\r
1868 there is a special helper for showing that content, called
\r
1869 <tt>git-ls-tree</tt>, which turns the binary content into a more easily
\r
1870 readable form.</p>
\r
1871 <p>It's especially instructive to look at "commit" objects, since those
\r
1872 tend to be small and fairly self-explanatory. In particular, if you
\r
1873 follow the convention of having the top commit name in <tt>.git/HEAD</tt>,
\r
1875 <div class="literalblock">
\r
1876 <div class="content">
\r
1877 <pre><tt>git-cat-file commit HEAD</tt></pre>
\r
1879 <p>to see what the top commit was.</p>
\r
1880 <h3>7) Merging multiple trees</h3>
\r
1881 <p>Git helps you do a three-way merge, which you can expand to n-way by
\r
1882 repeating the merge procedure arbitrary times until you finally
\r
1883 "commit" the state. The normal situation is that you'd only do one
\r
1884 three-way merge (two parents), and commit it, but if you like to, you
\r
1885 can do multiple parents in one go.</p>
\r
1886 <p>To do a three-way merge, you need the two sets of "commit" objects
\r
1887 that you want to merge, use those to find the closest common parent (a
\r
1888 third "commit" object), and then use those commit objects to find the
\r
1889 state of the directory ("tree" object) at these points.</p>
\r
1890 <p>To get the "base" for the merge, you first look up the common parent
\r
1891 of two commits with</p>
\r
1892 <div class="literalblock">
\r
1893 <div class="content">
\r
1894 <pre><tt>git-merge-base <commit1> <commit2></tt></pre>
\r
1896 <p>which will return you the commit they are both based on. You should
\r
1897 now look up the "tree" objects of those commits, which you can easily
\r
1898 do with (for example)</p>
\r
1899 <div class="literalblock">
\r
1900 <div class="content">
\r
1901 <pre><tt>git-cat-file commit <commitname> | head -1</tt></pre>
\r
1903 <p>since the tree object information is always the first line in a commit
\r
1905 <p>Once you know the three trees you are going to merge (the one
\r
1906 "original" tree, aka the common case, and the two "result" trees, aka
\r
1907 the branches you want to merge), you do a "merge" read into the
\r
1908 index. This will complain if it has to throw away your old index contents, so you should
\r
1909 make sure that you've committed those - in fact you would normally
\r
1910 always do a merge against your last commit (which should thus match
\r
1911 what you have in your current index anyway).</p>
\r
1912 <p>To do the merge, do</p>
\r
1913 <div class="literalblock">
\r
1914 <div class="content">
\r
1915 <pre><tt>git-read-tree -m -u <origtree> <yourtree> <targettree></tt></pre>
\r
1917 <p>which will do all trivial merge operations for you directly in the
\r
1918 index file, and you can just write the result out with
\r
1919 <tt>git-write-tree</tt>.</p>
\r
1920 <p>Historical note. We did not have <tt>-u</tt> facility when this
\r
1921 section was first written, so we used to warn that
\r
1922 the merge is done in the index file, not in your
\r
1923 working tree, and your working tree will not match your
\r
1924 index after this step.
\r
1925 This is no longer true. The above command, thanks to <tt>-u</tt>
\r
1926 option, updates your working tree with the merge results for
\r
1927 paths that have been trivially merged.</p>
\r
1928 <h3>8) Merging multiple trees, continued</h3>
\r
1929 <p>Sadly, many merges aren't trivial. If there are files that have
\r
1930 been added.moved or removed, or if both branches have modified the
\r
1931 same file, you will be left with an index tree that contains "merge
\r
1932 entries" in it. Such an index tree can <em>NOT</em> be written out to a tree
\r
1933 object, and you will have to resolve any such merge clashes using
\r
1934 other tools before you can write out the result.</p>
\r
1935 <p>You can examine such index state with <tt>git-ls-files --unmerged</tt>
\r
1936 command. An example:</p>
\r
1937 <div class="listingblock">
\r
1938 <div class="content">
\r
1939 <pre><tt>$ git-read-tree -m $orig HEAD $target
\r
1940 $ git-ls-files --unmerged
\r
1941 100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello.c
\r
1942 100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello.c
\r
1943 100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello.c</tt></pre>
\r
1945 <p>Each line of the <tt>git-ls-files --unmerged</tt> output begins with
\r
1946 the blob mode bits, blob SHA1, <em>stage number</em>, and the
\r
1947 filename. The <em>stage number</em> is git's way to say which tree it
\r
1948 came from: stage 1 corresponds to <tt>$orig</tt> tree, stage 2 <tt>HEAD</tt>
\r
1949 tree, and stage3 <tt>$target</tt> tree.</p>
\r
1950 <p>Earlier we said that trivial merges are done inside
\r
1951 <tt>git-read-tree -m</tt>. For example, if the file did not change
\r
1952 from <tt>$orig</tt> to <tt>HEAD</tt> nor <tt>$target</tt>, or if the file changed
\r
1953 from <tt>$orig</tt> to <tt>HEAD</tt> and <tt>$orig</tt> to <tt>$target</tt> the same way,
\r
1954 obviously the final outcome is what is in <tt>HEAD</tt>. What the
\r
1955 above example shows is that file <tt>hello.c</tt> was changed from
\r
1956 <tt>$orig</tt> to <tt>HEAD</tt> and <tt>$orig</tt> to <tt>$target</tt> in a different way.
\r
1957 You could resolve this by running your favorite 3-way merge
\r
1958 program, e.g. <tt>diff3</tt> or <tt>merge</tt>, on the blob objects from
\r
1959 these three stages yourself, like this:</p>
\r
1960 <div class="listingblock">
\r
1961 <div class="content">
\r
1962 <pre><tt>$ git-cat-file blob 263414f... >hello.c~1
\r
1963 $ git-cat-file blob 06fa6a2... >hello.c~2
\r
1964 $ git-cat-file blob cc44c73... >hello.c~3
\r
1965 $ merge hello.c~2 hello.c~1 hello.c~3</tt></pre>
\r
1967 <p>This would leave the merge result in <tt>hello.c~2</tt> file, along
\r
1968 with conflict markers if there are conflicts. After verifying
\r
1969 the merge result makes sense, you can tell git what the final
\r
1970 merge result for this file is by:</p>
\r
1971 <div class="literalblock">
\r
1972 <div class="content">
\r
1973 <pre><tt>mv -f hello.c~2 hello.c
\r
1974 git-update-index hello.c</tt></pre>
\r
1976 <p>When a path is in unmerged state, running <tt>git-update-index</tt> for
\r
1977 that path tells git to mark the path resolved.</p>
\r
1978 <p>The above is the description of a git merge at the lowest level,
\r
1979 to help you understand what conceptually happens under the hood.
\r
1980 In practice, nobody, not even git itself, uses three <tt>git-cat-file</tt>
\r
1981 for this. There is <tt>git-merge-index</tt> program that extracts the
\r
1982 stages to temporary files and calls a "merge" script on it:</p>
\r
1983 <div class="literalblock">
\r
1984 <div class="content">
\r
1985 <pre><tt>git-merge-index git-merge-one-file hello.c</tt></pre>
\r
1987 <p>and that is what higher level <tt>git resolve</tt> is implemented with.</p>
\r
1990 <div class="sectionbody">
\r
1994 git's founding father is Linus Torvalds <torvalds@osdl.org>.
\r
1999 The current git nurse is Junio C Hamano <junkio@cox.net>.
\r
2004 The git potty was written by Andres Ericsson <ae@op5.se>.
\r
2009 General upbringing is handled by the git-list <git@vger.kernel.org>.
\r
2014 <h2>Documentation</h2>
\r
2015 <div class="sectionbody">
\r
2016 <p>The documentation for git suite was started by David Greaves
\r
2017 <david@dgreaves.com>, and later enhanced greatly by the
\r
2018 contributors on the git-list <git@vger.kernel.org>.</p>
\r
2021 <div class="sectionbody">
\r
2022 <p>Part of the <a href="git.html">git(7)</a> suite</p>
\r
2025 <div id="footer-text">
\r
2026 Last updated 03-Apr-2006 05:33:34 UTC
\r