@matheusbsbs / matheus-bagliano / commits / b181d57ff4
Fork 0

user-manual: reorganize fetch discussion, add internals, etc.

Keep git remote discussion in the first chapter, but postpone lower-level git fetch usage (to fetch individual branches) till later. Import a bunch of slightly modified text from the readme to give an architectural overview at the end. Add more discussion of history rewriting. And a bunch of other miscellaneous changes.... Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>

J. Bruce Fields committed Jan 27, 2007 at 01:03 UTC b181d57ff40d94799a595045718039dc9d4320f7
1 file changed +954 -204
Documentation/user-manual.txt
+954 -204
@@ -5,7 +5,7 @@ This manual is designed to be readable by someone with basic unix
5 commandline skills, but no previous knowledge of git.
6
7 Chapter 1 gives a brief overview of git commands, without any
8 -explanation; you can skip to chapter 2 on a first reading.
8 +explanation; you may prefer to skip to chapter 2 on a first reading.
9
10 Chapters 2 and 3 explain how to fetch and study a project using
11 git--the tools you'd need to build and test a particular version of a
@@ -99,16 +99,16 @@ Keep a list of repositories you work with regularly:
99
100 -----------------------------------------------
101 $ git remote add example git://example.com/project.git
102 -$ git remote # list remote repositories
102 +$ git remote # list remote repositories
103 example
104 origin
105 -$ git remote show example # get details
105 +$ git remote show example # get details
106 * remote example
107 URL: git://example.com/project.git
108 Tracked remote branches
109 master next ...
110 -$ git fetch example # update branches from example
111 -$ git branch -r # list all remote branches
110 +$ git fetch example # update branches from example
111 +$ git branch -r # list all remote branches
112 -----------------------------------------------
113
114
@@ -134,7 +134,7 @@ $ git grep v2.6.15 "foo()" # search old tree for "foo()"
134 $ git show v2.6.15:a.txt # look at old version of a.txt
135 -----------------------------------------------
136
137 -Searching for regressions:
137 +Search for regressions:
138
139 -----------------------------------------------
140 $ git bisect start
@@ -173,7 +173,7 @@ $ git commit
173 Or, prepare and create the commit in one step:
174
175 -----------------------------------------------
176 -$ git commit d.txt # use latest content of d.txt
176 +$ git commit d.txt # use latest content only of d.txt
177 $ git commit -a # use latest content of all tracked files
178 -----------------------------------------------
179
@@ -232,6 +232,21 @@ $ git remote add example ssh://example.com/project.git
232 $ git push example test
233 -----------------------------------------------
234
235 +Repository maintenance
236 +----------------------
237 +
238 +Check for corruption:
239 +
240 +-----------------------------------------------
241 +$ git fsck-objects
242 +-----------------------------------------------
243 +
244 +Recompress, remove unused cruft:
245 +
246 +-----------------------------------------------
247 +$ git gc
248 +-----------------------------------------------
249 +
250 Repositories and Branches
251 =========================
252
@@ -376,13 +391,15 @@ index 8be626f..d7aac9d 100644
391 As you can see, a commit shows who made the latest change, what they
392 did, and why.
393
379 -Every commit has a 40-hexdigit id, sometimes called the "SHA1 id", shown
380 -on the first line of the "git show" output. You can usually refer to
381 -a commit by a shorter name, such as a tag or a branch name, but this
382 -longer id can also be useful. In particular, it is a globally unique
383 -name for this commit: so if you tell somebody else the SHA1 id (for
384 -example in email), then you are guaranteed they will see the same
385 -commit in their repository that you do in yours.
394 +Every commit has a 40-hexdigit id, sometimes called the "object name"
395 +or the "SHA1 id", shown on the first line of the "git show" output.
396 +You can usually refer to a commit by a shorter name, such as a tag or a
397 +branch name, but this longer name can also be useful. Most
398 +importantly, it is a globally unique name for this commit: so if you
399 +tell somebody else the object name (for example in email), then you are
400 +guaranteed that name will refer to the same commit in their repository
401 +that you it does in yours (assuming their repository has that commit at
402 +all).
403
404 Understanding history: commits, parents, and reachability
405 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -588,152 +605,6 @@ This is what causes git to track the remote's branches; you may
605 modify or delete these configuration options by editing .git/config
606 with a text editor.
607
591 -Fetching individual branches
592 -----------------------------
593 -
594 -TODO: find another home for this, later on:
595 -
596 -You can also choose to update just one branch at a time:
597 -
598 --------------------------------------------------
599 -$ git fetch origin todo:refs/remotes/origin/todo
600 --------------------------------------------------
601 -
602 -The first argument, "origin", just tells git to fetch from the
603 -repository you originally cloned from. The second argument tells git
604 -to fetch the branch named "todo" from the remote repository, and to
605 -store it locally under the name refs/remotes/origin/todo; as we saw
606 -above, remote-tracking branches are stored under
607 -refs/remotes/<name-of-repository>/<name-of-branch>.
608 -
609 -You can also fetch branches from other repositories; so
610 -
611 --------------------------------------------------
612 -$ git fetch git://example.com/proj.git master:refs/remotes/example/master
613 --------------------------------------------------
614 -
615 -will create a new reference named "refs/remotes/example/master" and
616 -store in it the branch named "master" from the repository at the
617 -given URL. If you already have a branch named
618 -"refs/remotes/example/master", it will attempt to "fast-forward" to
619 -the commit given by example.com's master branch. So next we explain
620 -what a fast-forward is:
621 -
622 -[[fast-forwards]]
623 -Understanding git history: fast-forwards
624 -----------------------------------------
625 -
626 -In the previous example, when updating an existing branch, "git
627 -fetch" checks to make sure that the most recent commit on the remote
628 -branch is a descendant of the most recent commit on your copy of the
629 -branch before updating your copy of the branch to point at the new
630 -commit. Git calls this process a "fast forward".
631 -
632 -A fast forward looks something like this:
633 -
634 - o--o--o--o <-- old head of the branch
635 - \
636 - o--o--o <-- new head of the branch
637 -
638 -
639 -In some cases it is possible that the new head will *not* actually be
640 -a descendant of the old head. For example, the developer may have
641 -realized she made a serious mistake, and decided to backtrack,
642 -resulting in a situation like:
643 -
644 - o--o--o--o--a--b <-- old head of the branch
645 - \
646 - o--o--o <-- new head of the branch
647 -
648 -
649 -
650 -In this case, "git fetch" will fail, and print out a warning.
651 -
652 -In that case, you can still force git to update to the new head, as
653 -described in the following section. However, note that in the
654 -situation above this may mean losing the commits labeled "a" and "b",
655 -unless you've already created a reference of your own pointing to
656 -them.
657 -
658 -Forcing git fetch to do non-fast-forward updates
659 -------------------------------------------------
660 -
661 -If git fetch fails because the new head of a branch is not a
662 -descendant of the old head, you may force the update with:
663 -
664 --------------------------------------------------
665 -$ git fetch git://example.com/proj.git +master:refs/remotes/example/master
666 --------------------------------------------------
667 -
668 -Note the addition of the "+" sign. Be aware that commits which the
669 -old version of example/master pointed at may be lost, as we saw in
670 -the previous section.
671 -
672 -Configuring remote branches
673 ----------------------------
674 -
675 -We saw above that "origin" is just a shortcut to refer to the
676 -repository which you originally cloned from. This information is
677 -stored in git configuration variables, which you can see using
678 -gitlink:git-repo-config[1]:
679 -
680 --------------------------------------------------
681 -$ git-repo-config -l
682 -core.repositoryformatversion=0
683 -core.filemode=true
684 -core.logallrefupdates=true
685 -remote.origin.url=git://git.kernel.org/pub/scm/git/git.git
686 -remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
687 -branch.master.remote=origin
688 -branch.master.merge=refs/heads/master
689 --------------------------------------------------
690 -
691 -If there are other repositories that you also use frequently, you can
692 -create similar configuration options to save typing; for example,
693 -after
694 -
695 --------------------------------------------------
696 -$ git repo-config remote.example.url git://example.com/proj.git
697 --------------------------------------------------
698 -
699 -then the following two commands will do the same thing:
700 -
701 --------------------------------------------------
702 -$ git fetch git://example.com/proj.git master:refs/remotes/example/master
703 -$ git fetch example master:refs/remotes/example/master
704 --------------------------------------------------
705 -
706 -Even better, if you add one more option:
707 -
708 --------------------------------------------------
709 -$ git repo-config remote.example.fetch master:refs/remotes/example/master
710 --------------------------------------------------
711 -
712 -then the following commands will all do the same thing:
713 -
714 --------------------------------------------------
715 -$ git fetch git://example.com/proj.git master:ref/remotes/example/master
716 -$ git fetch example master:ref/remotes/example/master
717 -$ git fetch example example/master
718 -$ git fetch example
719 --------------------------------------------------
720 -
721 -You can also add a "+" to force the update each time:
722 -
723 --------------------------------------------------
724 -$ git repo-config remote.example.fetch +master:ref/remotes/example/master
725 --------------------------------------------------
726 -
727 -Don't do this unless you're sure you won't mind "git fetch" possibly
728 -throwing away commits on mybranch.
729 -
730 -Also note that all of the above configuration can be performed by
731 -directly editing the file .git/config instead of using
732 -gitlink:git-repo-config[1].
733 -
734 -See gitlink:git-repo-config[1] for more details on the configuration
735 -options mentioned above.
736 -
608 Exploring git history
609 =====================
610
@@ -1008,8 +879,8 @@ $ git log origin...master
879
880 will return no commits when the two branches are equal.
881
1011 -Check which tagged version a given fix was first included in
1012 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
882 +Find first tagged version including a given fix
883 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
884
885 Suppose you know that the commit e05db0fd fixed a certain problem.
886 You'd like to find the earliest tagged release that contains that
@@ -1025,7 +896,47 @@ You could just visually inspect the commits since e05db0fd:
896 $ gitk e05db0fd..
897 -------------------------------------------------
898
1028 -...
899 +Or you can use gitlink:git-name-rev[1], which will give the commit a
900 +name based on any tag it finds pointing to one of the commit's
901 +descendants:
902 +
903 +-------------------------------------------------
904 +$ git name-rev e05db0fd
905 +e05db0fd tags/v1.5.0-rc1^0~23
906 +-------------------------------------------------
907 +
908 +The gitlink:git-describe[1] command does the opposite, naming the
909 +revision using a tag on which the given commit is based:
910 +
911 +-------------------------------------------------
912 +$ git describe e05db0fd
913 +v1.5.0-rc0-ge05db0f
914 +-------------------------------------------------
915 +
916 +but that may sometimes help you guess which tags might come after the
917 +given commit.
918 +
919 +If you just want to verify whether a given tagged version contains a
920 +given commit, you could use gitlink:git-merge-base[1]:
921 +
922 +-------------------------------------------------
923 +$ git merge-base e05db0fd v1.5.0-rc1
924 +e05db0fd4f31dde7005f075a84f96b360d05984b
925 +-------------------------------------------------
926 +
927 +The merge-base command finds a common ancestor of the given commits,
928 +and always returns one or the other in the case where one is a
929 +descendant of the other; so the above output shows that e05db0fd
930 +actually is an ancestor of v1.5.0-rc1.
931 +
932 +Alternatively, note that
933 +
934 +-------------------------------------------------
935 +$ git log v1.5.0-rc1..305db0fd
936 +-------------------------------------------------
937 +
938 +will produce empty output if and only if v1.5.0-rc1 includes 305db0fd,
939 +because it outputs only commits that are not reachable from v1.5.0-rc1.
940
941 Developing with git
942 ===================
@@ -1775,7 +1686,7 @@ TODO: topic branches, typical roles as in everyday.txt, ?
1686 Working with other version control systems
1687 ==========================================
1688
1778 -TODO: CVS, Subversion, series-of-release-tarballs, ?
1689 +TODO: CVS, Subversion, series-of-release-tarballs, etc.
1690
1691 [[cleaning-up-history]]
1692 Rewriting history and maintaining patch series
@@ -1796,8 +1707,8 @@ complicated feature, and to present it to the other developers in a way
1707 that makes it easy for them to read your changes, verify that they are
1708 correct, and understand why you made each change.
1709
1799 -If you present all of your changes as a single patch (or commit), they may
1800 -find it is too much to digest all at once.
1710 +If you present all of your changes as a single patch (or commit), they
1711 +may find it is too much to digest all at once.
1712
1713 If you present them with the entire history of your work, complete with
1714 mistakes, corrections, and dead ends, they may be overwhelmed.
@@ -1816,9 +1727,9 @@ So the ideal is usually to produce a series of patches such that:
1727 4. The complete series produces the same end result as your own
1728 (probably much messier!) development process did.
1729
1819 -We will introduce some tools that can help you do this, explain how to use
1820 -them, and then explain some of the problems that can arise because you are
1821 -rewriting history.
1730 +We will introduce some tools that can help you do this, explain how to
1731 +use them, and then explain some of the problems that can arise because
1732 +you are rewriting history.
1733
1734 Keeping a patch series up to date using git-rebase
1735 --------------------------------------------------
@@ -1826,8 +1737,8 @@ Keeping a patch series up to date using git-rebase
1737 Suppose you have a series of commits in a branch "mywork", which
1738 originally branched off from "origin".
1739
1829 -Suppose you create a branch "mywork" on a remote-tracking branch "origin",
1830 -and created some commits on top of it:
1740 +Suppose you create a branch "mywork" on a remote-tracking branch
1741 +"origin", and created some commits on top of it:
1742
1743 -------------------------------------------------
1744 $ git checkout -b mywork origin
@@ -1870,26 +1781,20 @@ $ git checkout mywork
1781 $ git rebase origin
1782 -------------------------------------------------
1783
1873 -This will remove each of your commits from mywork, temporarily saving them
1874 -as patches (in a directory named ".dotest"), update mywork to point at the
1875 -latest version of origin, then apply each of the saved patches to the new
1876 -mywork. The result will look like:
1784 +This will remove each of your commits from mywork, temporarily saving
1785 +them as patches (in a directory named ".dotest"), update mywork to
1786 +point at the latest version of origin, then apply each of the saved
1787 +patches to the new mywork. The result will look like:
1788
1789
1790 o--o--O--o--o--o <-- origin
1791 \
1792 a'--b'--c' <-- mywork
1793
1883 -In the process, it may discover conflicts. In that case it will stop and
1884 -allow you to fix the conflicts as described in
1885 -"<<resolving-a-merge,Resolving a merge>>".
1886 -
1887 -XXX: no, maybe not: git diff doesn't produce very useful results, and there's
1888 -no MERGE_HEAD.
1889 -
1890 -Once the index is updated with
1891 -the results of the conflict resolution, instead of creating a new commit,
1892 -just run
1794 +In the process, it may discover conflicts. In that case it will stop
1795 +and allow you to fix the conflicts; after fixing conflicts, use "git
1796 +add" to update the index with those contents, and then, instead of
1797 +running git-commit, just run
1798
1799 -------------------------------------------------
1800 $ git rebase --continue
@@ -1907,36 +1812,886 @@ $ git rebase --abort
1812 Reordering or selecting from a patch series
1813 -------------------------------------------
1814
1910 -Given one existing commit, the gitlink:git-cherry-pick[1] command allows
1911 -you to apply the change introduced by that commit and create a new commit
1912 -that records it.
1815 +Given one existing commit, the gitlink:git-cherry-pick[1] command
1816 +allows you to apply the change introduced by that commit and create a
1817 +new commit that records it. So, for example, if "mywork" points to a
1818 +series of patches on top of "origin", you might do something like:
1819 +
1820 +-------------------------------------------------
1821 +$ git checkout -b mywork-new origin
1822 +$ gitk origin..mywork &
1823 +-------------------------------------------------
1824 +
1825 +And browse through the list of patches in the mywork branch using gitk,
1826 +applying them (possibly in a different order) to mywork-new using
1827 +cherry-pick, and possibly modifying them as you go using commit
1828 +--amend.
1829 +
1830 +Another technique is to use git-format-patch to create a series of
1831 +patches, then reset the state to before the patches:
1832
1914 -This can be useful for modifying a patch series.
1833 +-------------------------------------------------
1834 +$ git format-patch origin
1835 +$ git reset --hard origin
1836 +-------------------------------------------------
1837
1916 -TODO: elaborate
1838 +Then modify, reorder, or eliminate patches as preferred before applying
1839 +them again with gitlink:git-am[1].
1840
1841 Other tools
1842 -----------
1843
1921 -There are numerous other tools, such as stgit, which exist for the purpose
1922 -of maintianing a patch series. These are out of the scope of this manual.
1844 +There are numerous other tools, such as stgit, which exist for the
1845 +purpose of maintaining a patch series. These are out of the scope of
1846 +this manual.
1847
1848 Problems with rewriting history
1849 -------------------------------
1850
1927 -The primary problem with rewriting the history of a branch has to do with
1928 -merging.
1851 +The primary problem with rewriting the history of a branch has to do
1852 +with merging. Suppose somebody fetches your branch and merges it into
1853 +their branch, with a result something like this:
1854 +
1855 + o--o--O--o--o--o <-- origin
1856 + \ \
1857 + t--t--t--m <-- their branch:
1858 +
1859 +Then suppose you modify the last three commits:
1860 +
1861 + o--o--o <-- new head of origin
1862 + /
1863 + o--o--O--o--o--o <-- old head of origin
1864 +
1865 +If we examined all this history together in one repository, it will
1866 +look like:
1867 +
1868 + o--o--o <-- new head of origin
1869 + /
1870 + o--o--O--o--o--o <-- old head of origin
1871 + \ \
1872 + t--t--t--m <-- their branch:
1873 +
1874 +Git has no way of knowing that the new head is an updated version of
1875 +the old head; it treats this situation exactly the same as it would if
1876 +two developers had independently done the work on the old and new heads
1877 +in parallel. At this point, if someone attempts to merge the new head
1878 +in to their branch, git will attempt to merge together the two (old and
1879 +new) lines of development, instead of trying to replace the old by the
1880 +new. The results are likely to be unexpected.
1881 +
1882 +You may still choose to publish branches whose history is rewritten,
1883 +and it may be useful for others to be able to fetch those branches in
1884 +order to examine or test them, but they should not attempt to pull such
1885 +branches into their own work.
1886 +
1887 +For true distributed development that supports proper merging,
1888 +published branches should never be rewritten.
1889 +
1890 +Advanced branch management
1891 +==========================
1892
1930 -TODO: elaborate
1893 +Fetching individual branches
1894 +----------------------------
1895 +
1896 +Instead of using gitlink:git-remote[1], you can also choose just
1897 +to update one branch at a time, and to store it locally under an
1898 +arbitrary name:
1899 +
1900 +-------------------------------------------------
1901 +$ git fetch origin todo:my-todo-work
1902 +-------------------------------------------------
1903 +
1904 +The first argument, "origin", just tells git to fetch from the
1905 +repository you originally cloned from. The second argument tells git
1906 +to fetch the branch named "todo" from the remote repository, and to
1907 +store it locally under the name refs/heads/my-todo-work.
1908 +
1909 +You can also fetch branches from other repositories; so
1910 +
1911 +-------------------------------------------------
1912 +$ git fetch git://example.com/proj.git master:example-master
1913 +-------------------------------------------------
1914 +
1915 +will create a new branch named "example-master" and store in it the
1916 +branch named "master" from the repository at the given URL. If you
1917 +already have a branch named example-master, it will attempt to
1918 +"fast-forward" to the commit given by example.com's master branch. So
1919 +next we explain what a fast-forward is:
1920 +
1921 +[[fast-forwards]]
1922 +Understanding git history: fast-forwards
1923 +----------------------------------------
1924 +
1925 +In the previous example, when updating an existing branch, "git
1926 +fetch" checks to make sure that the most recent commit on the remote
1927 +branch is a descendant of the most recent commit on your copy of the
1928 +branch before updating your copy of the branch to point at the new
1929 +commit. Git calls this process a "fast forward".
1930 +
1931 +A fast forward looks something like this:
1932 +
1933 + o--o--o--o <-- old head of the branch
1934 + \
1935 + o--o--o <-- new head of the branch
1936 +
1937 +
1938 +In some cases it is possible that the new head will *not* actually be
1939 +a descendant of the old head. For example, the developer may have
1940 +realized she made a serious mistake, and decided to backtrack,
1941 +resulting in a situation like:
1942 +
1943 + o--o--o--o--a--b <-- old head of the branch
1944 + \
1945 + o--o--o <-- new head of the branch
1946 +
1947 +
1948 +
1949 +In this case, "git fetch" will fail, and print out a warning.
1950 +
1951 +In that case, you can still force git to update to the new head, as
1952 +described in the following section. However, note that in the
1953 +situation above this may mean losing the commits labeled "a" and "b",
1954 +unless you've already created a reference of your own pointing to
1955 +them.
1956 +
1957 +Forcing git fetch to do non-fast-forward updates
1958 +------------------------------------------------
1959 +
1960 +If git fetch fails because the new head of a branch is not a
1961 +descendant of the old head, you may force the update with:
1962 +
1963 +-------------------------------------------------
1964 +$ git fetch git://example.com/proj.git +master:refs/remotes/example/master
1965 +-------------------------------------------------
1966 +
1967 +Note the addition of the "+" sign. Be aware that commits which the
1968 +old version of example/master pointed at may be lost, as we saw in
1969 +the previous section.
1970 +
1971 +Configuring remote branches
1972 +---------------------------
1973 +
1974 +We saw above that "origin" is just a shortcut to refer to the
1975 +repository which you originally cloned from. This information is
1976 +stored in git configuration variables, which you can see using
1977 +gitlink:git-repo-config[1]:
1978 +
1979 +-------------------------------------------------
1980 +$ git-repo-config -l
1981 +core.repositoryformatversion=0
1982 +core.filemode=true
1983 +core.logallrefupdates=true
1984 +remote.origin.url=git://git.kernel.org/pub/scm/git/git.git
1985 +remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
1986 +branch.master.remote=origin
1987 +branch.master.merge=refs/heads/master
1988 +-------------------------------------------------
1989 +
1990 +If there are other repositories that you also use frequently, you can
1991 +create similar configuration options to save typing; for example,
1992 +after
1993 +
1994 +-------------------------------------------------
1995 +$ git repo-config remote.example.url git://example.com/proj.git
1996 +-------------------------------------------------
1997 +
1998 +then the following two commands will do the same thing:
1999 +
2000 +-------------------------------------------------
2001 +$ git fetch git://example.com/proj.git master:refs/remotes/example/master
2002 +$ git fetch example master:refs/remotes/example/master
2003 +-------------------------------------------------
2004 +
2005 +Even better, if you add one more option:
2006 +
2007 +-------------------------------------------------
2008 +$ git repo-config remote.example.fetch master:refs/remotes/example/master
2009 +-------------------------------------------------
2010 +
2011 +then the following commands will all do the same thing:
2012 +
2013 +-------------------------------------------------
2014 +$ git fetch git://example.com/proj.git master:ref/remotes/example/master
2015 +$ git fetch example master:ref/remotes/example/master
2016 +$ git fetch example example/master
2017 +$ git fetch example
2018 +-------------------------------------------------
2019 +
2020 +You can also add a "+" to force the update each time:
2021 +
2022 +-------------------------------------------------
2023 +$ git repo-config remote.example.fetch +master:ref/remotes/example/master
2024 +-------------------------------------------------
2025 +
2026 +Don't do this unless you're sure you won't mind "git fetch" possibly
2027 +throwing away commits on mybranch.
2028 +
2029 +Also note that all of the above configuration can be performed by
2030 +directly editing the file .git/config instead of using
2031 +gitlink:git-repo-config[1].
2032 +
2033 +See gitlink:git-repo-config[1] for more details on the configuration
2034 +options mentioned above.
2035
2036
2037 Git internals
2038 =============
2039
1936 -Architectural overview
2040 +There are two object abstractions: the "object database", and the
2041 +"current directory cache" aka "index".
2042 +
2043 +The Object Database
2044 +-------------------
2045 +
2046 +The object database is literally just a content-addressable collection
2047 +of objects. All objects are named by their content, which is
2048 +approximated by the SHA1 hash of the object itself. Objects may refer
2049 +to other objects (by referencing their SHA1 hash), and so you can
2050 +build up a hierarchy of objects.
2051 +
2052 +All objects have a statically determined "type" aka "tag", which is
2053 +determined at object creation time, and which identifies the format of
2054 +the object (i.e. how it is used, and how it can refer to other
2055 +objects). There are currently four different object types: "blob",
2056 +"tree", "commit" and "tag".
2057 +
2058 +A "blob" object cannot refer to any other object, and is, like the type
2059 +implies, a pure storage object containing some user data. It is used to
2060 +actually store the file data, i.e. a blob object is associated with some
2061 +particular version of some file.
2062 +
2063 +A "tree" object is an object that ties one or more "blob" objects into a
2064 +directory structure. In addition, a tree object can refer to other tree
2065 +objects, thus creating a directory hierarchy.
2066 +
2067 +A "commit" object ties such directory hierarchies together into
2068 +a DAG of revisions - each "commit" is associated with exactly one tree
2069 +(the directory hierarchy at the time of the commit). In addition, a
2070 +"commit" refers to one or more "parent" commit objects that describe the
2071 +history of how we arrived at that directory hierarchy.
2072 +
2073 +As a special case, a commit object with no parents is called the "root"
2074 +object, and is the point of an initial project commit. Each project
2075 +must have at least one root, and while you can tie several different
2076 +root objects together into one project by creating a commit object which
2077 +has two or more separate roots as its ultimate parents, that's probably
2078 +just going to confuse people. So aim for the notion of "one root object
2079 +per project", even if git itself does not enforce that.
2080 +
2081 +A "tag" object symbolically identifies and can be used to sign other
2082 +objects. It contains the identifier and type of another object, a
2083 +symbolic name (of course!) and, optionally, a signature.
2084 +
2085 +Regardless of object type, all objects share the following
2086 +characteristics: they are all deflated with zlib, and have a header
2087 +that not only specifies their type, but also provides size information
2088 +about the data in the object. It's worth noting that the SHA1 hash
2089 +that is used to name the object is the hash of the original data
2090 +plus this header, so `sha1sum` 'file' does not match the object name
2091 +for 'file'.
2092 +(Historical note: in the dawn of the age of git the hash
2093 +was the sha1 of the 'compressed' object.)
2094 +
2095 +As a result, the general consistency of an object can always be tested
2096 +independently of the contents or the type of the object: all objects can
2097 +be validated by verifying that (a) their hashes match the content of the
2098 +file and (b) the object successfully inflates to a stream of bytes that
2099 +forms a sequence of <ascii type without space> + <space> + <ascii decimal
2100 +size> + <byte\0> + <binary object data>.
2101 +
2102 +The structured objects can further have their structure and
2103 +connectivity to other objects verified. This is generally done with
2104 +the `git-fsck-objects` program, which generates a full dependency graph
2105 +of all objects, and verifies their internal consistency (in addition
2106 +to just verifying their superficial consistency through the hash).
2107 +
2108 +The object types in some more detail:
2109 +
2110 +Blob Object
2111 +-----------
2112 +
2113 +A "blob" object is nothing but a binary blob of data, and doesn't
2114 +refer to anything else. There is no signature or any other
2115 +verification of the data, so while the object is consistent (it 'is'
2116 +indexed by its sha1 hash, so the data itself is certainly correct), it
2117 +has absolutely no other attributes. No name associations, no
2118 +permissions. It is purely a blob of data (i.e. normally "file
2119 +contents").
2120 +
2121 +In particular, since the blob is entirely defined by its data, if two
2122 +files in a directory tree (or in multiple different versions of the
2123 +repository) have the same contents, they will share the same blob
2124 +object. The object is totally independent of its location in the
2125 +directory tree, and renaming a file does not change the object that
2126 +file is associated with in any way.
2127 +
2128 +A blob is typically created when gitlink:git-update-index[1]
2129 +is run, and its data can be accessed by gitlink:git-cat-file[1].
2130 +
2131 +Tree Object
2132 +-----------
2133 +
2134 +The next hierarchical object type is the "tree" object. A tree object
2135 +is a list of mode/name/blob data, sorted by name. Alternatively, the
2136 +mode data may specify a directory mode, in which case instead of
2137 +naming a blob, that name is associated with another TREE object.
2138 +
2139 +Like the "blob" object, a tree object is uniquely determined by the
2140 +set contents, and so two separate but identical trees will always
2141 +share the exact same object. This is true at all levels, i.e. it's
2142 +true for a "leaf" tree (which does not refer to any other trees, only
2143 +blobs) as well as for a whole subdirectory.
2144 +
2145 +For that reason a "tree" object is just a pure data abstraction: it
2146 +has no history, no signatures, no verification of validity, except
2147 +that since the contents are again protected by the hash itself, we can
2148 +trust that the tree is immutable and its contents never change.
2149 +
2150 +So you can trust the contents of a tree to be valid, the same way you
2151 +can trust the contents of a blob, but you don't know where those
2152 +contents 'came' from.
2153 +
2154 +Side note on trees: since a "tree" object is a sorted list of
2155 +"filename+content", you can create a diff between two trees without
2156 +actually having to unpack two trees. Just ignore all common parts,
2157 +and your diff will look right. In other words, you can effectively
2158 +(and efficiently) tell the difference between any two random trees by
2159 +O(n) where "n" is the size of the difference, rather than the size of
2160 +the tree.
2161 +
2162 +Side note 2 on trees: since the name of a "blob" depends entirely and
2163 +exclusively on its contents (i.e. there are no names or permissions
2164 +involved), you can see trivial renames or permission changes by
2165 +noticing that the blob stayed the same. However, renames with data
2166 +changes need a smarter "diff" implementation.
2167 +
2168 +A tree is created with gitlink:git-write-tree[1] and
2169 +its data can be accessed by gitlink:git-ls-tree[1].
2170 +Two trees can be compared with gitlink:git-diff-tree[1].
2171 +
2172 +Commit Object
2173 +-------------
2174 +
2175 +The "commit" object is an object that introduces the notion of
2176 +history into the picture. In contrast to the other objects, it
2177 +doesn't just describe the physical state of a tree, it describes how
2178 +we got there, and why.
2179 +
2180 +A "commit" is defined by the tree-object that it results in, the
2181 +parent commits (zero, one or more) that led up to that point, and a
2182 +comment on what happened. Again, a commit is not trusted per se:
2183 +the contents are well-defined and "safe" due to the cryptographically
2184 +strong signatures at all levels, but there is no reason to believe
2185 +that the tree is "good" or that the merge information makes sense.
2186 +The parents do not have to actually have any relationship with the
2187 +result, for example.
2188 +
2189 +Note on commits: unlike real SCM's, commits do not contain
2190 +rename information or file mode change information. All of that is
2191 +implicit in the trees involved (the result tree, and the result trees
2192 +of the parents), and describing that makes no sense in this idiotic
2193 +file manager.
2194 +
2195 +A commit is created with gitlink:git-commit-tree[1] and
2196 +its data can be accessed by gitlink:git-cat-file[1].
2197 +
2198 +Trust
2199 +-----
2200 +
2201 +An aside on the notion of "trust". Trust is really outside the scope
2202 +of "git", but it's worth noting a few things. First off, since
2203 +everything is hashed with SHA1, you 'can' trust that an object is
2204 +intact and has not been messed with by external sources. So the name
2205 +of an object uniquely identifies a known state - just not a state that
2206 +you may want to trust.
2207 +
2208 +Furthermore, since the SHA1 signature of a commit refers to the
2209 +SHA1 signatures of the tree it is associated with and the signatures
2210 +of the parent, a single named commit specifies uniquely a whole set
2211 +of history, with full contents. You can't later fake any step of the
2212 +way once you have the name of a commit.
2213 +
2214 +So to introduce some real trust in the system, the only thing you need
2215 +to do is to digitally sign just 'one' special note, which includes the
2216 +name of a top-level commit. Your digital signature shows others
2217 +that you trust that commit, and the immutability of the history of
2218 +commits tells others that they can trust the whole history.
2219 +
2220 +In other words, you can easily validate a whole archive by just
2221 +sending out a single email that tells the people the name (SHA1 hash)
2222 +of the top commit, and digitally sign that email using something
2223 +like GPG/PGP.
2224 +
2225 +To assist in this, git also provides the tag object...
2226 +
2227 +Tag Object
2228 +----------
2229 +
2230 +Git provides the "tag" object to simplify creating, managing and
2231 +exchanging symbolic and signed tokens. The "tag" object at its
2232 +simplest simply symbolically identifies another object by containing
2233 +the sha1, type and symbolic name.
2234 +
2235 +However it can optionally contain additional signature information
2236 +(which git doesn't care about as long as there's less than 8k of
2237 +it). This can then be verified externally to git.
2238 +
2239 +Note that despite the tag features, "git" itself only handles content
2240 +integrity; the trust framework (and signature provision and
2241 +verification) has to come from outside.
2242 +
2243 +A tag is created with gitlink:git-mktag[1],
2244 +its data can be accessed by gitlink:git-cat-file[1],
2245 +and the signature can be verified by
2246 +gitlink:git-verify-tag[1].
2247 +
2248 +
2249 +The "index" aka "Current Directory Cache"
2250 +-----------------------------------------
2251 +
2252 +The index is a simple binary file, which contains an efficient
2253 +representation of a virtual directory content at some random time. It
2254 +does so by a simple array that associates a set of names, dates,
2255 +permissions and content (aka "blob") objects together. The cache is
2256 +always kept ordered by name, and names are unique (with a few very
2257 +specific rules) at any point in time, but the cache has no long-term
2258 +meaning, and can be partially updated at any time.
2259 +
2260 +In particular, the index certainly does not need to be consistent with
2261 +the current directory contents (in fact, most operations will depend on
2262 +different ways to make the index 'not' be consistent with the directory
2263 +hierarchy), but it has three very important attributes:
2264 +
2265 +'(a) it can re-generate the full state it caches (not just the
2266 +directory structure: it contains pointers to the "blob" objects so
2267 +that it can regenerate the data too)'
2268 +
2269 +As a special case, there is a clear and unambiguous one-way mapping
2270 +from a current directory cache to a "tree object", which can be
2271 +efficiently created from just the current directory cache without
2272 +actually looking at any other data. So a directory cache at any one
2273 +time uniquely specifies one and only one "tree" object (but has
2274 +additional data to make it easy to match up that tree object with what
2275 +has happened in the directory)
2276 +
2277 +'(b) it has efficient methods for finding inconsistencies between that
2278 +cached state ("tree object waiting to be instantiated") and the
2279 +current state.'
2280 +
2281 +'(c) it can additionally efficiently represent information about merge
2282 +conflicts between different tree objects, allowing each pathname to be
2283 +associated with sufficient information about the trees involved that
2284 +you can create a three-way merge between them.'
2285 +
2286 +Those are the three ONLY things that the directory cache does. It's a
2287 +cache, and the normal operation is to re-generate it completely from a
2288 +known tree object, or update/compare it with a live tree that is being
2289 +developed. If you blow the directory cache away entirely, you generally
2290 +haven't lost any information as long as you have the name of the tree
2291 +that it described.
2292 +
2293 +At the same time, the index is at the same time also the
2294 +staging area for creating new trees, and creating a new tree always
2295 +involves a controlled modification of the index file. In particular,
2296 +the index file can have the representation of an intermediate tree that
2297 +has not yet been instantiated. So the index can be thought of as a
2298 +write-back cache, which can contain dirty information that has not yet
2299 +been written back to the backing store.
2300 +
2301 +
2302 +
2303 +The Workflow
2304 +------------
2305 +
2306 +Generally, all "git" operations work on the index file. Some operations
2307 +work *purely* on the index file (showing the current state of the
2308 +index), but most operations move data to and from the index file. Either
2309 +from the database or from the working directory. Thus there are four
2310 +main combinations:
2311 +
2312 +working directory -> index
2313 +~~~~~~~~~~~~~~~~~~~~~~~~~~
2314 +
2315 +You update the index with information from the working directory with
2316 +the gitlink:git-update-index[1] command. You
2317 +generally update the index information by just specifying the filename
2318 +you want to update, like so:
2319 +
2320 +-------------------------------------------------
2321 +$ git-update-index filename
2322 +-------------------------------------------------
2323 +
2324 +but to avoid common mistakes with filename globbing etc, the command
2325 +will not normally add totally new entries or remove old entries,
2326 +i.e. it will normally just update existing cache entries.
2327 +
2328 +To tell git that yes, you really do realize that certain files no
2329 +longer exist, or that new files should be added, you
2330 +should use the `--remove` and `--add` flags respectively.
2331 +
2332 +NOTE! A `--remove` flag does 'not' mean that subsequent filenames will
2333 +necessarily be removed: if the files still exist in your directory
2334 +structure, the index will be updated with their new status, not
2335 +removed. The only thing `--remove` means is that update-cache will be
2336 +considering a removed file to be a valid thing, and if the file really
2337 +does not exist any more, it will update the index accordingly.
2338 +
2339 +As a special case, you can also do `git-update-index --refresh`, which
2340 +will refresh the "stat" information of each index to match the current
2341 +stat information. It will 'not' update the object status itself, and
2342 +it will only update the fields that are used to quickly test whether
2343 +an object still matches its old backing store object.
2344 +
2345 +index -> object database
2346 +~~~~~~~~~~~~~~~~~~~~~~~~
2347 +
2348 +You write your current index file to a "tree" object with the program
2349 +
2350 +-------------------------------------------------
2351 +$ git-write-tree
2352 +-------------------------------------------------
2353 +
2354 +that doesn't come with any options - it will just write out the
2355 +current index into the set of tree objects that describe that state,
2356 +and it will return the name of the resulting top-level tree. You can
2357 +use that tree to re-generate the index at any time by going in the
2358 +other direction:
2359 +
2360 +object database -> index
2361 +~~~~~~~~~~~~~~~~~~~~~~~~
2362 +
2363 +You read a "tree" file from the object database, and use that to
2364 +populate (and overwrite - don't do this if your index contains any
2365 +unsaved state that you might want to restore later!) your current
2366 +index. Normal operation is just
2367 +
2368 +-------------------------------------------------
2369 +$ git-read-tree <sha1 of tree>
2370 +-------------------------------------------------
2371 +
2372 +and your index file will now be equivalent to the tree that you saved
2373 +earlier. However, that is only your 'index' file: your working
2374 +directory contents have not been modified.
2375 +
2376 +index -> working directory
2377 +~~~~~~~~~~~~~~~~~~~~~~~~~~
2378 +
2379 +You update your working directory from the index by "checking out"
2380 +files. This is not a very common operation, since normally you'd just
2381 +keep your files updated, and rather than write to your working
2382 +directory, you'd tell the index files about the changes in your
2383 +working directory (i.e. `git-update-index`).
2384 +
2385 +However, if you decide to jump to a new version, or check out somebody
2386 +else's version, or just restore a previous tree, you'd populate your
2387 +index file with read-tree, and then you need to check out the result
2388 +with
2389 +
2390 +-------------------------------------------------
2391 +$ git-checkout-index filename
2392 +-------------------------------------------------
2393 +
2394 +or, if you want to check out all of the index, use `-a`.
2395 +
2396 +NOTE! git-checkout-index normally refuses to overwrite old files, so
2397 +if you have an old version of the tree already checked out, you will
2398 +need to use the "-f" flag ('before' the "-a" flag or the filename) to
2399 +'force' the checkout.
2400 +
2401 +
2402 +Finally, there are a few odds and ends which are not purely moving
2403 +from one representation to the other:
2404 +
2405 +Tying it all together
2406 +~~~~~~~~~~~~~~~~~~~~~
2407 +
2408 +To commit a tree you have instantiated with "git-write-tree", you'd
2409 +create a "commit" object that refers to that tree and the history
2410 +behind it - most notably the "parent" commits that preceded it in
2411 +history.
2412 +
2413 +Normally a "commit" has one parent: the previous state of the tree
2414 +before a certain change was made. However, sometimes it can have two
2415 +or more parent commits, in which case we call it a "merge", due to the
2416 +fact that such a commit brings together ("merges") two or more
2417 +previous states represented by other commits.
2418 +
2419 +In other words, while a "tree" represents a particular directory state
2420 +of a working directory, a "commit" represents that state in "time",
2421 +and explains how we got there.
2422 +
2423 +You create a commit object by giving it the tree that describes the
2424 +state at the time of the commit, and a list of parents:
2425 +
2426 +-------------------------------------------------
2427 +$ git-commit-tree <tree> -p <parent> [-p <parent2> ..]
2428 +-------------------------------------------------
2429 +
2430 +and then giving the reason for the commit on stdin (either through
2431 +redirection from a pipe or file, or by just typing it at the tty).
2432 +
2433 +git-commit-tree will return the name of the object that represents
2434 +that commit, and you should save it away for later use. Normally,
2435 +you'd commit a new `HEAD` state, and while git doesn't care where you
2436 +save the note about that state, in practice we tend to just write the
2437 +result to the file pointed at by `.git/HEAD`, so that we can always see
2438 +what the last committed state was.
2439 +
2440 +Here is an ASCII art by Jon Loeliger that illustrates how
2441 +various pieces fit together.
2442 +
2443 +------------
2444 +
2445 + commit-tree
2446 + commit obj
2447 + +----+
2448 + | |
2449 + | |
2450 + V V
2451 + +-----------+
2452 + | Object DB |
2453 + | Backing |
2454 + | Store |
2455 + +-----------+
2456 + ^
2457 + write-tree | |
2458 + tree obj | |
2459 + | | read-tree
2460 + | | tree obj
2461 + V
2462 + +-----------+
2463 + | Index |
2464 + | "cache" |
2465 + +-----------+
2466 + update-index ^
2467 + blob obj | |
2468 + | |
2469 + checkout-index -u | | checkout-index
2470 + stat | | blob obj
2471 + V
2472 + +-----------+
2473 + | Working |
2474 + | Directory |
2475 + +-----------+
2476 +
2477 +------------
2478 +
2479 +
2480 +Examining the data
2481 +------------------
2482 +
2483 +You can examine the data represented in the object database and the
2484 +index with various helper tools. For every object, you can use
2485 +gitlink:git-cat-file[1] to examine details about the
2486 +object:
2487 +
2488 +-------------------------------------------------
2489 +$ git-cat-file -t <objectname>
2490 +-------------------------------------------------
2491 +
2492 +shows the type of the object, and once you have the type (which is
2493 +usually implicit in where you find the object), you can use
2494 +
2495 +-------------------------------------------------
2496 +$ git-cat-file blob|tree|commit|tag <objectname>
2497 +-------------------------------------------------
2498 +
2499 +to show its contents. NOTE! Trees have binary content, and as a result
2500 +there is a special helper for showing that content, called
2501 +`git-ls-tree`, which turns the binary content into a more easily
2502 +readable form.
2503 +
2504 +It's especially instructive to look at "commit" objects, since those
2505 +tend to be small and fairly self-explanatory. In particular, if you
2506 +follow the convention of having the top commit name in `.git/HEAD`,
2507 +you can do
2508 +
2509 +-------------------------------------------------
2510 +$ git-cat-file commit HEAD
2511 +-------------------------------------------------
2512 +
2513 +to see what the top commit was.
2514 +
2515 +Merging multiple trees
2516 ----------------------
2517
1939 -TODO: Sources, README, core-tutorial, tutorial-2.txt, technical/
2518 +Git helps you do a three-way merge, which you can expand to n-way by
2519 +repeating the merge procedure arbitrary times until you finally
2520 +"commit" the state. The normal situation is that you'd only do one
2521 +three-way merge (two parents), and commit it, but if you like to, you
2522 +can do multiple parents in one go.
2523 +
2524 +To do a three-way merge, you need the two sets of "commit" objects
2525 +that you want to merge, use those to find the closest common parent (a
2526 +third "commit" object), and then use those commit objects to find the
2527 +state of the directory ("tree" object) at these points.
2528 +
2529 +To get the "base" for the merge, you first look up the common parent
2530 +of two commits with
2531 +
2532 +-------------------------------------------------
2533 +$ git-merge-base <commit1> <commit2>
2534 +-------------------------------------------------
2535 +
2536 +which will return you the commit they are both based on. You should
2537 +now look up the "tree" objects of those commits, which you can easily
2538 +do with (for example)
2539 +
2540 +-------------------------------------------------
2541 +$ git-cat-file commit <commitname> | head -1
2542 +-------------------------------------------------
2543 +
2544 +since the tree object information is always the first line in a commit
2545 +object.
2546 +
2547 +Once you know the three trees you are going to merge (the one
2548 +"original" tree, aka the common case, and the two "result" trees, aka
2549 +the branches you want to merge), you do a "merge" read into the
2550 +index. This will complain if it has to throw away your old index contents, so you should
2551 +make sure that you've committed those - in fact you would normally
2552 +always do a merge against your last commit (which should thus match
2553 +what you have in your current index anyway).
2554 +
2555 +To do the merge, do
2556 +
2557 +-------------------------------------------------
2558 +$ git-read-tree -m -u <origtree> <yourtree> <targettree>
2559 +-------------------------------------------------
2560 +
2561 +which will do all trivial merge operations for you directly in the
2562 +index file, and you can just write the result out with
2563 +`git-write-tree`.
2564 +
2565 +
2566 +Merging multiple trees, continued
2567 +---------------------------------
2568 +
2569 +Sadly, many merges aren't trivial. If there are files that have
2570 +been added.moved or removed, or if both branches have modified the
2571 +same file, you will be left with an index tree that contains "merge
2572 +entries" in it. Such an index tree can 'NOT' be written out to a tree
2573 +object, and you will have to resolve any such merge clashes using
2574 +other tools before you can write out the result.
2575 +
2576 +You can examine such index state with `git-ls-files --unmerged`
2577 +command. An example:
2578 +
2579 +------------------------------------------------
2580 +$ git-read-tree -m $orig HEAD $target
2581 +$ git-ls-files --unmerged
2582 +100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello.c
2583 +100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello.c
2584 +100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello.c
2585 +------------------------------------------------
2586 +
2587 +Each line of the `git-ls-files --unmerged` output begins with
2588 +the blob mode bits, blob SHA1, 'stage number', and the
2589 +filename. The 'stage number' is git's way to say which tree it
2590 +came from: stage 1 corresponds to `$orig` tree, stage 2 `HEAD`
2591 +tree, and stage3 `$target` tree.
2592 +
2593 +Earlier we said that trivial merges are done inside
2594 +`git-read-tree -m`. For example, if the file did not change
2595 +from `$orig` to `HEAD` nor `$target`, or if the file changed
2596 +from `$orig` to `HEAD` and `$orig` to `$target` the same way,
2597 +obviously the final outcome is what is in `HEAD`. What the
2598 +above example shows is that file `hello.c` was changed from
2599 +`$orig` to `HEAD` and `$orig` to `$target` in a different way.
2600 +You could resolve this by running your favorite 3-way merge
2601 +program, e.g. `diff3` or `merge`, on the blob objects from
2602 +these three stages yourself, like this:
2603 +
2604 +------------------------------------------------
2605 +$ git-cat-file blob 263414f... >hello.c~1
2606 +$ git-cat-file blob 06fa6a2... >hello.c~2
2607 +$ git-cat-file blob cc44c73... >hello.c~3
2608 +$ merge hello.c~2 hello.c~1 hello.c~3
2609 +------------------------------------------------
2610 +
2611 +This would leave the merge result in `hello.c~2` file, along
2612 +with conflict markers if there are conflicts. After verifying
2613 +the merge result makes sense, you can tell git what the final
2614 +merge result for this file is by:
2615 +
2616 +-------------------------------------------------
2617 +$ mv -f hello.c~2 hello.c
2618 +$ git-update-index hello.c
2619 +-------------------------------------------------
2620 +
2621 +When a path is in unmerged state, running `git-update-index` for
2622 +that path tells git to mark the path resolved.
2623 +
2624 +The above is the description of a git merge at the lowest level,
2625 +to help you understand what conceptually happens under the hood.
2626 +In practice, nobody, not even git itself, uses three `git-cat-file`
2627 +for this. There is `git-merge-index` program that extracts the
2628 +stages to temporary files and calls a "merge" script on it:
2629 +
2630 +-------------------------------------------------
2631 +$ git-merge-index git-merge-one-file hello.c
2632 +-------------------------------------------------
2633 +
2634 +and that is what higher level `git resolve` is implemented with.
2635 +
2636 +How git stores objects efficiently: pack files
2637 +----------------------------------------------
2638 +
2639 +We've seen how git stores each object in a file named after the
2640 +object's SHA1 hash.
2641 +
2642 +Unfortunately this system becomes inefficient once a project has a
2643 +lot of objects. Try this on an old project:
2644 +
2645 +------------------------------------------------
2646 +$ git count-objects
2647 +6930 objects, 47620 kilobytes
2648 +------------------------------------------------
2649 +
2650 +The first number is the number of objects which are kept in
2651 +individual files. The second is the amount of space taken up by
2652 +those "loose" objects.
2653 +
2654 +You can save space and make git faster by moving these loose objects in
2655 +to a "pack file", which stores a group of objects in an efficient
2656 +compressed format; the details of how pack files are formatted can be
2657 +found in link:technical/pack-format.txt[technical/pack-format.txt].
2658 +
2659 +To put the loose objects into a pack, just run git repack:
2660 +
2661 +------------------------------------------------
2662 +$ git repack
2663 +Generating pack...
2664 +Done counting 6020 objects.
2665 +Deltifying 6020 objects.
2666 + 100% (6020/6020) done
2667 +Writing 6020 objects.
2668 + 100% (6020/6020) done
2669 +Total 6020, written 6020 (delta 4070), reused 0 (delta 0)
2670 +Pack pack-3e54ad29d5b2e05838c75df582c65257b8d08e1c created.
2671 +------------------------------------------------
2672 +
2673 +You can then run
2674 +
2675 +------------------------------------------------
2676 +$ git prune
2677 +------------------------------------------------
2678 +
2679 +to remove any of the "loose" objects that are now contained in the
2680 +pack. This will also remove any unreferenced objects (which may be
2681 +created when, for example, you use "git reset" to remove a commit).
2682 +You can verify that the loose objects are gone by looking at the
2683 +.git/objects directory or by running
2684 +
2685 +------------------------------------------------
2686 +$ git count-objects
2687 +0 objects, 0 kilobytes
2688 +------------------------------------------------
2689 +
2690 +Although the object files are gone, any commands that refer to those
2691 +objects will work exactly as they did before.
2692 +
2693 +The gitlink:git-gc[1] command performs packing, pruning, and more for
2694 +you, so is normally the only high-level command you need.
2695
2696 Glossary of git terms
2697 =====================
@@ -1976,15 +2731,12 @@ Scan man pages to see if any assume more background than this manual
2731 provides.
2732
2733 Simplify beginning by suggesting disconnected head instead of
1979 -temporary branch creation.
2734 +temporary branch creation?
2735
2736 Explain how to refer to file stages in the "how to resolve a merge"
2737 section: diff -1, -2, -3, --ours, --theirs :1:/path notation. The
2738 "git ls-files --unmerged --stage" thing is sorta useful too,
1984 -actually. And note gitk --merge. Also what's easiest way to see
1985 -common merge base? Note also text where I claim rebase and am
1986 -conflicts are resolved like merges isn't generally true, at least by
1987 -default--fix.
2739 +actually. And note gitk --merge.
2740
2741 Add more good examples. Entire sections of just cookbook examples
2742 might be a good idea; maybe make an "advanced examples" section a
@@ -1992,8 +2744,6 @@ standard end-of-chapter section?
2744
2745 Include cross-references to the glossary, where appropriate.
2746
1995 -Add quickstart as first chapter.
1996 -
2747 To document:
2748 reflogs, git reflog expire
2749 shallow clones?? See draft 1.5.0 release notes for some documentation.