-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Git User's Manual (for version 1.5.1 or newer)</title><link rel="stylesheet" href="docbook-xsl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id232635"></a>Git User's Manual (for version 1.5.1 or newer)</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="preface"><a href="#id264704">Preface</a></span></dt><dt><span class="chapter"><a href="#id233155">1. Git Quick Start</a></span></dt><dd><dl><dt><span class="section"><a href="#id233166">Creating a new repository</a></span></dt><dt><span class="section"><a href="#id233198">Managing branches</a></span></dt><dt><span class="section"><a href="#id232446">Exploring history</a></span></dt><dt><span class="section"><a href="#id232489">Making changes</a></span></dt><dt><span class="section"><a href="#id233362">Merging</a></span></dt><dt><span class="section"><a href="#id233378">Sharing your changes</a></span></dt><dt><span class="section"><a href="#id233464">Repository maintenance</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id232663">2. Repositories and Branches</a></span></dt><dd><dl><dt><span class="section"><a href="#id232669">How to get a git repository</a></span></dt><dt><span class="section"><a href="#id232726">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#id273521">Understanding History: Commits</a></span></dt><dd><dl><dt><span class="section"><a href="#id273583">Understanding history: commits, parents, and reachability</a></span></dt><dt><span class="section"><a href="#id273623">Understanding history: History diagrams</a></span></dt><dt><span class="section"><a href="#id273651">Understanding history: What is a branch?</a></span></dt></dl></dd><dt><span class="section"><a href="#id273674">Manipulating branches</a></span></dt><dt><span class="section"><a href="#detached-head">Examining an old version without creating a new branch</a></span></dt><dt><span class="section"><a href="#id273970">Examining branches from a remote repository</a></span></dt><dt><span class="section"><a href="#how-git-stores-references">Naming branches, tags, and other references</a></span></dt><dt><span class="section"><a href="#Updating-a-repository-with-git-fetch">Updating a repository with git fetch</a></span></dt><dt><span class="section"><a href="#id274113">Fetching branches from other repositories</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id274187">3. Exploring git history</a></span></dt><dd><dl><dt><span class="section"><a href="#id274209">How to use bisect to find a regression</a></span></dt><dt><span class="section"><a href="#id274328">Naming commits</a></span></dt><dt><span class="section"><a href="#id274476">Creating tags</a></span></dt><dt><span class="section"><a href="#id274511">Browsing revisions</a></span></dt><dt><span class="section"><a href="#id274585">Generating diffs</a></span></dt><dt><span class="section"><a href="#id274628">Viewing old file versions</a></span></dt><dt><span class="section"><a href="#id274654">Examples</a></span></dt><dd><dl><dt><span class="section"><a href="#id274660">Check whether two branches point at the same history</a></span></dt><dt><span class="section"><a href="#id274712">Find first tagged version including a given fix</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id274876">4. Developing with git</a></span></dt><dd><dl><dt><span class="section"><a href="#id274882">Telling git your name</a></span></dt><dt><span class="section"><a href="#id274914">Creating a new repository</a></span></dt><dt><span class="section"><a href="#how-to-make-a-commit">How to make a commit</a></span></dt><dt><span class="section"><a href="#id275141">Creating good commit messages</a></span></dt><dt><span class="section"><a href="#id275157">How to merge</a></span></dt><dt><span class="section"><a href="#resolving-a-merge">Resolving a merge</a></span></dt><dd><dl><dt><span class="section"><a href="#id275294">Getting conflict-resolution help during a merge</a></span></dt></dl></dd><dt><span class="section"><a href="#undoing-a-merge">Undoing a merge</a></span></dt><dt><span class="section"><a href="#id275503">Fast-forward merges</a></span></dt><dt><span class="section"><a href="#id275531">Fixing mistakes</a></span></dt><dd><dl><dt><span class="section"><a href="#id275584">Fixing a mistake with a new commit</a></span></dt><dt><span class="section"><a href="#fixing-a-mistake-by-editing-history">Fixing a mistake by editing history</a></span></dt><dt><span class="section"><a href="#id275717">Checking out an old version of a file</a></span></dt></dl></dd><dt><span class="section"><a href="#id275775">Ensuring good performance</a></span></dt><dt><span class="section"><a href="#id275813">Ensuring reliability</a></span></dt><dd><dl><dt><span class="section"><a href="#id275818">Checking the repository for corruption</a></span></dt><dt><span class="section"><a href="#id275893">Recovering lost changes</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#id232226">5. Sharing development with others</a></span></dt><dd><dl><dt><span class="section"><a href="#getting-updates-with-git-pull">Getting updates with git pull</a></span></dt><dt><span class="section"><a href="#id276243">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#id276292">Importing patches to a project</a></span></dt><dt><span class="section"><a href="#setting-up-a-public-repository">Setting up a public repository</a></span></dt><dt><span class="section"><a href="#exporting-via-http">Exporting a git repository via http</a></span></dt><dt><span class="section"><a href="#exporting-via-git">Exporting a git repository via the git protocol</a></span></dt><dt><span class="section"><a href="#pushing-changes-to-a-public-repository">Pushing changes to a public repository</a></span></dt><dt><span class="section"><a href="#id276705">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#id276724">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#id276737">Examples</a></span></dt></dl></dd><dt><span class="chapter"><a href="#cleaning-up-history">6. Rewriting history and maintaining patch series</a></span></dt><dd><dl><dt><span class="section"><a href="#id276769">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#id276844">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#id276974">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#id277071">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#id277131">Other tools</a></span></dt><dt><span class="section"><a href="#id277144">Problems with rewriting history</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id277215">7. Advanced branch management</a></span></dt><dd><dl><dt><span class="section"><a href="#id277220">Fetching individual branches</a></span></dt><dt><span class="section"><a href="#fast-forwards">Understanding git history: fast-forwards</a></span></dt><dt><span class="section"><a href="#id277341">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#id277368">Configuring remote branches</a></span></dt></dl></dd><dt><span class="chapter"><a href="#git-internals">8. Git internals</a></span></dt><dd><dl><dt><span class="section"><a href="#id277506">The Object Database</a></span></dt><dt><span class="section"><a href="#id277659">Blob Object</a></span></dt><dt><span class="section"><a href="#id277703">Tree Object</a></span></dt><dt><span class="section"><a href="#id277780">Commit Object</a></span></dt><dt><span class="section"><a href="#id277827">Trust</a></span></dt><dt><span class="section"><a href="#id277878">Tag Object</a></span></dt><dt><span class="section"><a href="#id277924">The "index" aka "Current Directory Cache"</a></span></dt><dt><span class="section"><a href="#id277999">The Workflow</a></span></dt><dd><dl><dt><span class="section"><a href="#id278018">working directory -> index</a></span></dt><dt><span class="section"><a href="#id278108">index -> object database</a></span></dt><dt><span class="section"><a href="#id278136">object database -> index</a></span></dt><dt><span class="section"><a href="#id278167">index -> working directory</a></span></dt><dt><span class="section"><a href="#id278230">Tying it all together</a></span></dt></dl></dd><dt><span class="section"><a href="#id278325">Examining the data</a></span></dt><dt><span class="section"><a href="#id278403">Merging multiple trees</a></span></dt><dt><span class="section"><a href="#id278490">Merging multiple trees, continued</a></span></dt><dt><span class="section"><a href="#id278750">How git stores objects efficiently: pack files</a></span></dt><dt><span class="section"><a href="#dangling-objects">Dangling objects</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id279010">9. GIT Glossary</a></span></dt><dt><span class="chapter"><a href="#id282289">10. Notes and todo list for this manual</a></span></dt></dl></div><div class="preface" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id264704"></a>Preface</h2></div></div></div><p>This manual is designed to be readable by someone with basic unix
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Git User's Manual (for version 1.5.1 or newer)</title><link rel="stylesheet" href="docbook-xsl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id232635"></a>Git User's Manual (for version 1.5.1 or newer)</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="preface"><a href="#id264704">Preface</a></span></dt><dt><span class="chapter"><a href="#git-quick-start">1. Git Quick Start</a></span></dt><dd><dl><dt><span class="section"><a href="#quick-creating-a-new-repository">Creating a new repository</a></span></dt><dt><span class="section"><a href="#managing-branches">Managing branches</a></span></dt><dt><span class="section"><a href="#exploring-history">Exploring history</a></span></dt><dt><span class="section"><a href="#making-changes">Making changes</a></span></dt><dt><span class="section"><a href="#merging">Merging</a></span></dt><dt><span class="section"><a href="#sharing-your-changes">Sharing your changes</a></span></dt><dt><span class="section"><a href="#repository-maintenance">Repository maintenance</a></span></dt></dl></dd><dt><span class="chapter"><a href="#repositories-and-branches">2. Repositories and Branches</a></span></dt><dd><dl><dt><span class="section"><a href="#how-to-get-a-git-repository">How to get a git repository</a></span></dt><dt><span class="section"><a href="#how-to-check-out">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#understanding-commits">Understanding History: Commits</a></span></dt><dd><dl><dt><span class="section"><a href="#understanding-reachability">Understanding history: commits, parents, and reachability</a></span></dt><dt><span class="section"><a href="#history-diagrams">Understanding history: History diagrams</a></span></dt><dt><span class="section"><a href="#what-is-a-branch">Understanding history: What is a branch?</a></span></dt></dl></dd><dt><span class="section"><a href="#manipulating-branches">Manipulating branches</a></span></dt><dt><span class="section"><a href="#detached-head">Examining an old version without creating a new branch</a></span></dt><dt><span class="section"><a href="#examining-remote-branches">Examining branches from a remote repository</a></span></dt><dt><span class="section"><a href="#how-git-stores-references">Naming branches, tags, and other references</a></span></dt><dt><span class="section"><a href="#Updating-a-repository-with-git-fetch">Updating a repository with git fetch</a></span></dt><dt><span class="section"><a href="#fetching-branches">Fetching branches from other repositories</a></span></dt></dl></dd><dt><span class="chapter"><a href="#exploring-git-history">3. Exploring git history</a></span></dt><dd><dl><dt><span class="section"><a href="#using-bisect">How to use bisect to find a regression</a></span></dt><dt><span class="section"><a href="#naming-commits">Naming commits</a></span></dt><dt><span class="section"><a href="#creating-tags">Creating tags</a></span></dt><dt><span class="section"><a href="#browsing-revisions">Browsing revisions</a></span></dt><dt><span class="section"><a href="#generating-diffs">Generating diffs</a></span></dt><dt><span class="section"><a href="#viewing-old-file-versions">Viewing old file versions</a></span></dt><dt><span class="section"><a href="#history-examples">Examples</a></span></dt><dd><dl><dt><span class="section"><a href="#checking-for-equal-branches">Check whether two branches point at the same history</a></span></dt><dt><span class="section"><a href="#finding-tagged-descendants">Find first tagged version including a given fix</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#Developing-with-git">4. Developing with git</a></span></dt><dd><dl><dt><span class="section"><a href="#telling-git-your-name">Telling git your name</a></span></dt><dt><span class="section"><a href="#creating-a-new-repository">Creating a new repository</a></span></dt><dt><span class="section"><a href="#how-to-make-a-commit">How to make a commit</a></span></dt><dt><span class="section"><a href="#creating-good-commit-messages">Creating good commit messages</a></span></dt><dt><span class="section"><a href="#how-to-merge">How to merge</a></span></dt><dt><span class="section"><a href="#resolving-a-merge">Resolving a merge</a></span></dt><dd><dl><dt><span class="section"><a href="#conflict-resolution">Getting conflict-resolution help during a merge</a></span></dt></dl></dd><dt><span class="section"><a href="#undoing-a-merge">Undoing a merge</a></span></dt><dt><span class="section"><a href="#fast-forwards">Fast-forward merges</a></span></dt><dt><span class="section"><a href="#fixing-mistakes">Fixing mistakes</a></span></dt><dd><dl><dt><span class="section"><a href="#reverting-a-commit">Fixing a mistake with a new commit</a></span></dt><dt><span class="section"><a href="#fixing-a-mistake-by-editing-history">Fixing a mistake by editing history</a></span></dt><dt><span class="section"><a href="#checkout-of-path">Checking out an old version of a file</a></span></dt></dl></dd><dt><span class="section"><a href="#ensuring-good-performance">Ensuring good performance</a></span></dt><dt><span class="section"><a href="#ensuring-reliability">Ensuring reliability</a></span></dt><dd><dl><dt><span class="section"><a href="#checking-for-corruption">Checking the repository for corruption</a></span></dt><dt><span class="section"><a href="#recovering-lost-changes">Recovering lost changes</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#sharing-development">5. Sharing development with others</a></span></dt><dd><dl><dt><span class="section"><a href="#getting-updates-with-git-pull">Getting updates with git pull</a></span></dt><dt><span class="section"><a href="#submitting-patches">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#importing-patches">Importing patches to a project</a></span></dt><dt><span class="section"><a href="#setting-up-a-public-repository">Setting up a public repository</a></span></dt><dt><span class="section"><a href="#exporting-via-http">Exporting a git repository via http</a></span></dt><dt><span class="section"><a href="#exporting-via-git">Exporting a git repository via the git protocol</a></span></dt><dt><span class="section"><a href="#pushing-changes-to-a-public-repository">Pushing changes to a public repository</a></span></dt><dt><span class="section"><a href="#setting-up-a-shared-repository">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#setting-up-gitweb">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#sharing-development-examples">Examples</a></span></dt></dl></dd><dt><span class="chapter"><a href="#cleaning-up-history">6. Rewriting history and maintaining patch series</a></span></dt><dd><dl><dt><span class="section"><a href="#patch-series">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#using-git-rebase">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#modifying-one-commit">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#reordering-patch-series">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#patch-series-tools">Other tools</a></span></dt><dt><span class="section"><a href="#problems-with-rewriting-history">Problems with rewriting history</a></span></dt></dl></dd><dt><span class="chapter"><a href="#advanced-branch-management">7. Advanced branch management</a></span></dt><dd><dl><dt><span class="section"><a href="#fetching-individual-branches">Fetching individual branches</a></span></dt><dt><span class="section"><a href="#fetch-fast-forwards">git fetch and fast-forwards</a></span></dt><dt><span class="section"><a href="#forcing-fetch">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#remote-branch-configuration">Configuring remote branches</a></span></dt></dl></dd><dt><span class="chapter"><a href="#git-internals">8. Git internals</a></span></dt><dd><dl><dt><span class="section"><a href="#the-object-database">The Object Database</a></span></dt><dt><span class="section"><a href="#blob-object">Blob Object</a></span></dt><dt><span class="section"><a href="#tree-object">Tree Object</a></span></dt><dt><span class="section"><a href="#commit-object">Commit Object</a></span></dt><dt><span class="section"><a href="#trust">Trust</a></span></dt><dt><span class="section"><a href="#tag-object">Tag Object</a></span></dt><dt><span class="section"><a href="#the-index">The "index" aka "Current Directory Cache"</a></span></dt><dt><span class="section"><a href="#the-workflow">The Workflow</a></span></dt><dd><dl><dt><span class="section"><a href="#working-directory-to-index">working directory -> index</a></span></dt><dt><span class="section"><a href="#index-to-object-database">index -> object database</a></span></dt><dt><span class="section"><a href="#object-database-to-index">object database -> index</a></span></dt><dt><span class="section"><a href="#index-to-working-directory">index -> working directory</a></span></dt><dt><span class="section"><a href="#tying-it-all-together">Tying it all together</a></span></dt></dl></dd><dt><span class="section"><a href="#examining-the-data">Examining the data</a></span></dt><dt><span class="section"><a href="#merging-multiple-trees">Merging multiple trees</a></span></dt><dt><span class="section"><a href="#merging-multiple-trees-2">Merging multiple trees, continued</a></span></dt><dt><span class="section"><a href="#pack-files">How git stores objects efficiently: pack files</a></span></dt><dt><span class="section"><a href="#dangling-objects">Dangling objects</a></span></dt></dl></dd><dt><span class="chapter"><a href="#glossary">9. GIT Glossary</a></span></dt><dt><span class="chapter"><a href="#todo">10. Notes and todo list for this manual</a></span></dt></dl></div><div class="preface" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id264704"></a>Preface</h2></div></div></div><p>This manual is designed to be readable by someone with basic unix
command-line skills, but no previous knowledge of git.</p><p>Chapter 1 gives a brief overview of git commands, without any
explanation; you may prefer to skip to chapter 2 on a first reading.</p><p>Chapters 2 and 3 explain how to fetch and study a project using
git—the tools you'd need to build and test a particular version of a
software project, to search for regressions, and so on.</p><p>Chapter 4 explains how to do development with git, and chapter 5 how
to share that development with others.</p><p>Further chapters cover more specialized topics.</p><p>Comprehensive reference documentation is available through the man
-pages. For a command such as "git clone", just use</p><div class="literallayout"><p>$ man git-clone</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id233155"></a>Chapter 1. Git Quick Start</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id233166">Creating a new repository</a></span></dt><dt><span class="section"><a href="#id233198">Managing branches</a></span></dt><dt><span class="section"><a href="#id232446">Exploring history</a></span></dt><dt><span class="section"><a href="#id232489">Making changes</a></span></dt><dt><span class="section"><a href="#id233362">Merging</a></span></dt><dt><span class="section"><a href="#id233378">Sharing your changes</a></span></dt><dt><span class="section"><a href="#id233464">Repository maintenance</a></span></dt></dl></div><p>This is a quick summary of the major commands; the following chapters
-will explain how these work in more detail.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id233166"></a>Creating a new repository</h2></div></div></div><p>From a tarball:</p><div class="literallayout"><p>$ tar xzf project.tar.gz<br>
+pages. For a command such as "git clone", just use</p><div class="literallayout"><p>$ man git-clone</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="git-quick-start"></a>Chapter 1. Git Quick Start</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#quick-creating-a-new-repository">Creating a new repository</a></span></dt><dt><span class="section"><a href="#managing-branches">Managing branches</a></span></dt><dt><span class="section"><a href="#exploring-history">Exploring history</a></span></dt><dt><span class="section"><a href="#making-changes">Making changes</a></span></dt><dt><span class="section"><a href="#merging">Merging</a></span></dt><dt><span class="section"><a href="#sharing-your-changes">Sharing your changes</a></span></dt><dt><span class="section"><a href="#repository-maintenance">Repository maintenance</a></span></dt></dl></div><p>This is a quick summary of the major commands; the following chapters
+will explain how these work in more detail.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="quick-creating-a-new-repository"></a>Creating a new repository</h2></div></div></div><p>From a tarball:</p><div class="literallayout"><p>$ tar xzf project.tar.gz<br>
$ cd project<br>
$ git init<br>
Initialized empty Git repository in .git/<br>
$ git add .<br>
$ git commit</p></div><p>From a remote repository:</p><div class="literallayout"><p>$ git clone git://example.com/pub/project.git<br>
-$ cd project</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id233198"></a>Managing branches</h2></div></div></div><div class="literallayout"><p>$ git branch         # list all branches in this repo<br>
+$ cd project</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="managing-branches"></a>Managing branches</h2></div></div></div><div class="literallayout"><p>$ git branch         # list all local branches in this repo<br>
$ git checkout test  # switch working directory to branch "test"<br>
$ git branch new     # create branch "new" starting at current HEAD<br>
$ git branch -d new  # delete branch "new"</p></div><p>Instead of basing new branch on current HEAD (the default), use:</p><div class="literallayout"><p>$ git branch new test    # branch named "test"<br>
  Tracked remote branches<br>
    master next ...<br>
$ git fetch example             # update branches from example<br>
-$ git branch -r                 # list all remote branches</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id232446"></a>Exploring history</h2></div></div></div><div class="literallayout"><p>$ gitk                      # visualize and browse history<br>
+$ git branch -r                 # list all remote branches</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="exploring-history"></a>Exploring history</h2></div></div></div><div class="literallayout"><p>$ gitk                      # visualize and browse history<br>
$ git log                   # list all commits<br>
$ git log src/              # ...modifying src/<br>
$ git log v2.6.15..v2.6.16  # ...in v2.6.16, not in v2.6.15<br>
                                # test here, then:<br>
$ git bisect good               # if this revision is good, or<br>
$ git bisect bad                # if this revision is bad.<br>
-                                # repeat until done.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id232489"></a>Making changes</h2></div></div></div><p>Make sure git knows who to blame:</p><div class="literallayout"><p>$ cat >~/.gitconfig <<\EOF<br>
+                                # repeat until done.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="making-changes"></a>Making changes</h2></div></div></div><p>Make sure git knows who to blame:</p><div class="literallayout"><p>$ cat >>~/.gitconfig <<\EOF<br>
[user]<br>
        name = Your Name Comes Here<br>
        email = you@yourdomain.example.com<br>
$ git add b.txt    # new file<br>
$ git rm c.txt     # old file<br>
$ git commit</p></div><p>Or, prepare and create the commit in one step:</p><div class="literallayout"><p>$ git commit d.txt # use latest content only of d.txt<br>
-$ git commit -a    # use latest content of all tracked files</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id233362"></a>Merging</h2></div></div></div><div class="literallayout"><p>$ git merge test   # merge branch "test" into the current branch<br>
+$ git commit -a    # use latest content of all tracked files</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="merging"></a>Merging</h2></div></div></div><div class="literallayout"><p>$ git merge test   # merge branch "test" into the current branch<br>
$ git pull git://example.com/project.git master<br>
                   # fetch and merge in remote branch<br>
-$ git pull . test  # equivalent to git merge test</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id233378"></a>Sharing your changes</h2></div></div></div><p>Importing or exporting patches:</p><div class="literallayout"><p>$ git format-patch origin..HEAD # format a patch for each commit<br>
+$ git pull . test  # equivalent to git merge test</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sharing-your-changes"></a>Sharing your changes</h2></div></div></div><p>Importing or exporting patches:</p><div class="literallayout"><p>$ git format-patch origin..HEAD # format a patch for each commit<br>
                                # in HEAD but not in origin<br>
$ git am mbox # import patches from the mailbox "mbox"</p></div><p>Fetch a branch in a different git repository, then merge into the
current branch:</p><div class="literallayout"><p>$ git pull git://example.com/project.git theirbranch</p></div><p>Store the fetched branch into a local branch before merging into the
current branch:</p><div class="literallayout"><p>$ git pull git://example.com/project.git theirbranch:mybranch</p></div><p>After creating commits on a local branch, update the remote
branch with your commits:</p><div class="literallayout"><p>$ git push ssh://example.com/project.git mybranch:theirbranch</p></div><p>When remote and local branch are both named "test":</p><div class="literallayout"><p>$ git push ssh://example.com/project.git test</p></div><p>Shortcut version for a frequently used remote repository:</p><div class="literallayout"><p>$ git remote add example ssh://example.com/project.git<br>
-$ git push example test</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id233464"></a>Repository maintenance</h2></div></div></div><p>Check for corruption:</p><div class="literallayout"><p>$ git fsck</p></div><p>Recompress, remove unused cruft:</p><div class="literallayout"><p>$ git gc</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id232663"></a>Chapter 2. Repositories and Branches</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id232669">How to get a git repository</a></span></dt><dt><span class="section"><a href="#id232726">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#id273521">Understanding History: Commits</a></span></dt><dd><dl><dt><span class="section"><a href="#id273583">Understanding history: commits, parents, and reachability</a></span></dt><dt><span class="section"><a href="#id273623">Understanding history: History diagrams</a></span></dt><dt><span class="section"><a href="#id273651">Understanding history: What is a branch?</a></span></dt></dl></dd><dt><span class="section"><a href="#id273674">Manipulating branches</a></span></dt><dt><span class="section"><a href="#detached-head">Examining an old version without creating a new branch</a></span></dt><dt><span class="section"><a href="#id273970">Examining branches from a remote repository</a></span></dt><dt><span class="section"><a href="#how-git-stores-references">Naming branches, tags, and other references</a></span></dt><dt><span class="section"><a href="#Updating-a-repository-with-git-fetch">Updating a repository with git fetch</a></span></dt><dt><span class="section"><a href="#id274113">Fetching branches from other repositories</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id232669"></a>How to get a git repository</h2></div></div></div><p>It will be useful to have a git repository to experiment with as you
+$ git push example test</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="repository-maintenance"></a>Repository maintenance</h2></div></div></div><p>Check for corruption:</p><div class="literallayout"><p>$ git fsck</p></div><p>Recompress, remove unused cruft:</p><div class="literallayout"><p>$ git gc</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="repositories-and-branches"></a>Chapter 2. Repositories and Branches</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#how-to-get-a-git-repository">How to get a git repository</a></span></dt><dt><span class="section"><a href="#how-to-check-out">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#understanding-commits">Understanding History: Commits</a></span></dt><dd><dl><dt><span class="section"><a href="#understanding-reachability">Understanding history: commits, parents, and reachability</a></span></dt><dt><span class="section"><a href="#history-diagrams">Understanding history: History diagrams</a></span></dt><dt><span class="section"><a href="#what-is-a-branch">Understanding history: What is a branch?</a></span></dt></dl></dd><dt><span class="section"><a href="#manipulating-branches">Manipulating branches</a></span></dt><dt><span class="section"><a href="#detached-head">Examining an old version without creating a new branch</a></span></dt><dt><span class="section"><a href="#examining-remote-branches">Examining branches from a remote repository</a></span></dt><dt><span class="section"><a href="#how-git-stores-references">Naming branches, tags, and other references</a></span></dt><dt><span class="section"><a href="#Updating-a-repository-with-git-fetch">Updating a repository with git fetch</a></span></dt><dt><span class="section"><a href="#fetching-branches">Fetching branches from other repositories</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="how-to-get-a-git-repository"></a>How to get a git repository</h2></div></div></div><p>It will be useful to have a git repository to experiment with as you
read this manual.</p><p>The best way to get one is by using the <a href="git-clone.html" target="_top">git-clone(1)</a> command
to download a copy of an existing repository for a project that you
are interested in. If you don't already have a project in mind, here
directory, you will see that it contains a copy of the project files,
together with a special top-level directory named ".git", which
contains all the information about the history of the project.</p><p>In most of the following, examples will be taken from one of the two
-repositories above.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id232726"></a>How to check out a different version of a project</h2></div></div></div><p>Git is best thought of as a tool for storing the history of a
+repositories above.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="how-to-check-out"></a>How to check out a different version of a project</h2></div></div></div><p>Git is best thought of as a tool for storing the history of a
collection of files. It stores the history as a compressed
collection of interrelated snapshots (versions) of the project's
contents.</p><p>A single git repository may contain multiple branches. It keeps track
the current branch to point at v2.6.17 instead, with</p><div class="literallayout"><p>$ git reset --hard v2.6.17</p></div><p>Note that if the current branch head was your only reference to a
particular point in history, then resetting that branch may leave you
with no way to find the history it used to point to; so use this command
-carefully.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id273521"></a>Understanding History: Commits</h2></div></div></div><p>Every change in the history of a project is represented by a commit.
+carefully.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="understanding-commits"></a>Understanding History: Commits</h2></div></div></div><p>Every change in the history of a project is represented by a commit.
The <a href="git-show.html" target="_top">git-show(1)</a> command shows the most recent commit on the
current branch:</p><div class="literallayout"><p>$ git show<br>
commit 2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2<br>
contents of the commit, you are guaranteed that the commit can never change
without its name also changing.</p><p>In fact, in <a href="#git-internals" title="Chapter 8. Git internals">Chapter 8, <i>Git internals</i></a> we shall see that everything stored in git
history, including file data and directory contents, is stored in an object
-with a name that is a hash of its contents.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id273583"></a>Understanding history: commits, parents, and reachability</h3></div></div></div><p>Every commit (except the very first commit in a project) also has a
+with a name that is a hash of its contents.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="understanding-reachability"></a>Understanding history: commits, parents, and reachability</h3></div></div></div><p>Every commit (except the very first commit in a project) also has a
parent commit which shows what happened before this commit.
Following the chain of parents will eventually take you back to the
beginning of the project.</p><p>However, the commits do not form a simple list; git allows lines of
commits will help understand how the git organizes history.</p><p>In the following, we say that commit X is "reachable" from commit Y
if commit X is an ancestor of commit Y. Equivalently, you could say
that Y is a descendent of X, or that there is a chain of parents
-leading from commit Y to commit X.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id273623"></a>Understanding history: History diagrams</h3></div></div></div><p>We will sometimes represent git history using diagrams like the one
+leading from commit Y to commit X.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="history-diagrams"></a>Understanding history: History diagrams</h3></div></div></div><p>We will sometimes represent git history using diagrams like the one
below. Commits are shown as "o", and the links between them with
lines drawn with - / and \. Time goes left to right:</p><pre class="literallayout"> o--o--o <-- Branch A
/
o--o--o <-- master
\
o--o--o <-- Branch B</pre><p>If we need to talk about a particular commit, the character "o" may
-be replaced with another letter or number.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id273651"></a>Understanding history: What is a branch?</h3></div></div></div><p>When we need to be precise, we will use the word "branch" to mean a line
+be replaced with another letter or number.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="what-is-a-branch"></a>Understanding history: What is a branch?</h3></div></div></div><p>When we need to be precise, we will use the word "branch" to mean a line
of development, and "branch head" (or just "head") to mean a reference
to the most recent commit on a branch. In the example above, the branch
head named "A" is a pointer to one particular commit, but we refer to
the line of three commits leading up to that point as all being part of
"branch A".</p><p>However, when no confusion will result, we often just use the term
-"branch" both for branches and for branch heads.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id273674"></a>Manipulating branches</h2></div></div></div><p>Creating, deleting, and modifying branches is quick and easy; here's
+"branch" both for branches and for branch heads.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="manipulating-branches"></a>Manipulating branches</h2></div></div></div><p>Creating, deleting, and modifying branches is quick and easy; here's
a summary of the commands:</p><div class="variablelist"><dl><dt><span class="term">
git branch
</span></dt><dd>
git branch -d <branch>
</span></dt><dd>
delete the branch <branch>; if the branch you are deleting
- points to a commit which is not reachable from this branch,
- this command will fail with a warning.
+ points to a commit which is not reachable from the current
+ branch, this command will fail with a warning.
</dd><dt><span class="term">
git branch -D <branch>
</span></dt><dd>
HEAD is now at 427abfa... Linux v2.6.17</p></div><p>The HEAD then refers to the SHA1 of the commit instead of to a branch,
and git branch shows that you are no longer on a branch:</p><div class="literallayout"><p>$ cat .git/HEAD<br>
427abfa28afedffadfca9dd8b067eb6d36bac53f<br>
-git branch<br>
+$ git branch<br>
* (no branch)<br>
-Â Â master</p></div><p>In this case we say that the HEAD is "detached".</p><p>This can be an easy way to check out a particular version without having
-to make up a name for a new branch. However, keep in mind that when you
-switch away from the (for example, by checking out something else), you
-can lose track of what the HEAD used to point to.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id273970"></a>Examining branches from a remote repository</h2></div></div></div><p>The "master" branch that was created at the time you cloned is a copy
+Â Â master</p></div><p>In this case we say that the HEAD is "detached".</p><p>This is an easy way to check out a particular version without having to
+make up a name for the new branch. You can still create a new branch
+(or tag) for this version later if you decide to.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="examining-remote-branches"></a>Examining branches from a remote repository</h2></div></div></div><p>The "master" branch that was created at the time you cloned is a copy
of the HEAD in the repository that you cloned from. That repository
may also have had other branches, though, and your local repository
keeps branches which track each of those remote branches, which you
</li><li>
"origin/master" is short for "refs/remotes/origin/master".
</li></ul></div><p>The full name is occasionally useful if, for example, there ever
-exists a tag and a branch with the same name.</p><p>As another useful shortcut, if the repository "origin" posesses only
-a single branch, you can refer to that branch as just "origin".</p><p>More generally, if you have defined a remote repository named
-"example", you can refer to the branch in that repository as
-"example". And for a repository with multiple branches, this will
-refer to the branch designated as the "HEAD" branch.</p><p>For the complete list of paths which git checks for references, and
+exists a tag and a branch with the same name.</p><p>As another useful shortcut, the "HEAD" of a repository can be referred
+to just using the name of that repository. So, for example, "origin"
+is usually a shortcut for the HEAD branch in the repository "origin".</p><p>For the complete list of paths which git checks for references, and
the order it uses to decide which to choose when there are multiple
references with the same shorthand name, see the "SPECIFYING
REVISIONS" section of <a href="git-rev-parse.html" target="_top">git-rev-parse(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="Updating-a-repository-with-git-fetch"></a>Updating a repository with git fetch</h2></div></div></div><p>Eventually the developer cloned from will do additional work in her
at the new commits.</p><p>The command "git fetch", with no arguments, will update all of the
remote-tracking branches to the latest version found in her
repository. It will not touch any of your own branches—not even the
-"master" branch that was created for you on clone.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274113"></a>Fetching branches from other repositories</h2></div></div></div><p>You can also track branches from repositories other than the one you
+"master" branch that was created for you on clone.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fetching-branches"></a>Fetching branches from other repositories</h2></div></div></div><p>You can also track branches from repositories other than the one you
cloned from, using <a href="git-remote.html" target="_top">git-remote(1)</a>:</p><div class="literallayout"><p>$ git remote add linux-nfs git://linux-nfs.org/pub/nfs-2.6.git<br>
$ git fetch linux-nfs<br>
* refs/remotes/linux-nfs/master: storing branch 'master' ...<br>
...</p></div><p>This is what causes git to track the remote's branches; you may modify
or delete these configuration options by editing .git/config with a
text editor. (See the "CONFIGURATION FILE" section of
-<a href="git-config.html" target="_top">git-config(1)</a> for details.)</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id274187"></a>Chapter 3. Exploring git history</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id274209">How to use bisect to find a regression</a></span></dt><dt><span class="section"><a href="#id274328">Naming commits</a></span></dt><dt><span class="section"><a href="#id274476">Creating tags</a></span></dt><dt><span class="section"><a href="#id274511">Browsing revisions</a></span></dt><dt><span class="section"><a href="#id274585">Generating diffs</a></span></dt><dt><span class="section"><a href="#id274628">Viewing old file versions</a></span></dt><dt><span class="section"><a href="#id274654">Examples</a></span></dt><dd><dl><dt><span class="section"><a href="#id274660">Check whether two branches point at the same history</a></span></dt><dt><span class="section"><a href="#id274712">Find first tagged version including a given fix</a></span></dt></dl></dd></dl></div><p>Git is best thought of as a tool for storing the history of a
+<a href="git-config.html" target="_top">git-config(1)</a> for details.)</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="exploring-git-history"></a>Chapter 3. Exploring git history</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#using-bisect">How to use bisect to find a regression</a></span></dt><dt><span class="section"><a href="#naming-commits">Naming commits</a></span></dt><dt><span class="section"><a href="#creating-tags">Creating tags</a></span></dt><dt><span class="section"><a href="#browsing-revisions">Browsing revisions</a></span></dt><dt><span class="section"><a href="#generating-diffs">Generating diffs</a></span></dt><dt><span class="section"><a href="#viewing-old-file-versions">Viewing old file versions</a></span></dt><dt><span class="section"><a href="#history-examples">Examples</a></span></dt><dd><dl><dt><span class="section"><a href="#checking-for-equal-branches">Check whether two branches point at the same history</a></span></dt><dt><span class="section"><a href="#finding-tagged-descendants">Find first tagged version including a given fix</a></span></dt></dl></dd></dl></div><p>Git is best thought of as a tool for storing the history of a
collection of files. It does this by storing compressed snapshots of
the contents of a file heirarchy, together with "commits" which show
the relationships between these snapshots.</p><p>Git provides extremely flexible and fast tools for exploring the
history of a project.</p><p>We start with one specialized tool that is useful for finding the
-commit that introduced a bug into a project.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274209"></a>How to use bisect to find a regression</h2></div></div></div><p>Suppose version 2.6.18 of your project worked, but the version at
+commit that introduced a bug into a project.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="using-bisect"></a>How to use bisect to find a regression</h2></div></div></div><p>Suppose version 2.6.18 of your project worked, but the version at
"master" crashes. Sometimes the best way to find the cause of such a
regression is to perform a brute-force search through the project's
history to find the particular commit that caused the problem. The
run</p><div class="literallayout"><p>$ git bisect visualize</p></div><p>which will run gitk and label the commit it chose with a marker that
says "bisect". Chose a safe-looking commit nearby, note its commit
id, and check it out with:</p><div class="literallayout"><p>$ git reset --hard fb47ddb2db...</p></div><p>then test, run "bisect good" or "bisect bad" as appropriate, and
-continue.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274328"></a>Naming commits</h2></div></div></div><p>We have seen several ways of naming commits already:</p><div class="itemizedlist"><ul type="disc"><li>
+continue.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="naming-commits"></a>Naming commits</h2></div></div></div><p>We have seen several ways of naming commits already:</p><div class="itemizedlist"><ul type="disc"><li>
40-hexdigit object name
</li><li>
branch name: refers to the commit at the head of the given
branch.</p><p>The <a href="git-rev-parse.html" target="_top">git-rev-parse(1)</a> command is a low-level command that is
occasionally useful for translating some name for a commit to the object
name for that commit:</p><div class="literallayout"><p>$ git rev-parse origin<br>
-e05db0fd4f31dde7005f075a84f96b360d05984b</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274476"></a>Creating tags</h2></div></div></div><p>We can also create a tag to refer to a particular commit; after
-running</p><div class="literallayout"><p>$ git tag stable-1 1b2e1d63ff</p></div><p>You can use stable-1 to refer to the commit 1b2e1d63ff.</p><p>This creates a "lightweight" tag. If the tag is a tag you wish to
-share with others, and possibly sign cryptographically, then you
-should create a tag object instead; see the <a href="git-tag.html" target="_top">git-tag(1)</a> man
-page for details.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274511"></a>Browsing revisions</h2></div></div></div><p>The <a href="git-log.html" target="_top">git-log(1)</a> command can show lists of commits. On its
+e05db0fd4f31dde7005f075a84f96b360d05984b</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="creating-tags"></a>Creating tags</h2></div></div></div><p>We can also create a tag to refer to a particular commit; after
+running</p><div class="literallayout"><p>$ git tag stable-1 1b2e1d63ff</p></div><p>You can use stable-1 to refer to the commit 1b2e1d63ff.</p><p>This creates a "lightweight" tag. If you would also like to include a
+comment with the tag, and possibly sign it cryptographically, then you
+should create a tag object instead; see the <a href="git-tag.html" target="_top">git-tag(1)</a> man page
+for details.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="browsing-revisions"></a>Browsing revisions</h2></div></div></div><p>The <a href="git-log.html" target="_top">git-log(1)</a> command can show lists of commits. On its
own, it shows all commits reachable from the parent commit; but you
can also make more specific requests:</p><div class="literallayout"><p>$ git log v2.5..        # commits since (not reachable from) v2.5<br>
$ git log test..master  # commits reachable from master but not test<br>
display options.</p><p>Note that git log starts with the most recent commit and works
backwards through the parents; however, since git history can contain
multiple independent lines of development, the particular order that
-commits are listed in may be somewhat arbitrary.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274585"></a>Generating diffs</h2></div></div></div><p>You can generate diffs between any two versions using
+commits are listed in may be somewhat arbitrary.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="generating-diffs"></a>Generating diffs</h2></div></div></div><p>You can generate diffs between any two versions using
<a href="git-diff.html" target="_top">git-diff(1)</a>:</p><div class="literallayout"><p>$ git diff master..test</p></div><p>Sometimes what you want instead is a set of patches:</p><div class="literallayout"><p>$ git format-patch master..test</p></div><p>will generate a file with a patch for each commit reachable from test
but not from master. Note that if master also has commits which are
not reachable from test, then the combined result of these patches
-will not be the same as the diff produced by the git-diff example.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274628"></a>Viewing old file versions</h2></div></div></div><p>You can always view an old version of a file by just checking out the
+will not be the same as the diff produced by the git-diff example.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="viewing-old-file-versions"></a>Viewing old file versions</h2></div></div></div><p>You can always view an old version of a file by just checking out the
correct revision first. But sometimes it is more convenient to be
able to view an old version of a single file without checking
anything out; this command does that:</p><div class="literallayout"><p>$ git show v2.5:fs/locks.c</p></div><p>Before the colon may be anything that names a commit, and after it
-may be any path to a file tracked by git.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274654"></a>Examples</h2></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id274660"></a>Check whether two branches point at the same history</h3></div></div></div><p>Suppose you want to check whether two branches point at the same point
+may be any path to a file tracked by git.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="history-examples"></a>Examples</h2></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="checking-for-equal-branches"></a>Check whether two branches point at the same history</h3></div></div></div><p>Suppose you want to check whether two branches point at the same point
in history.</p><div class="literallayout"><p>$ git diff origin..master</p></div><p>will tell you whether the contents of the project are the same at the
two branches; in theory, however, it's possible that the same project
contents could have been arrived at by two different historical
$ git rev-list master<br>
e05db0fd4f31dde7005f075a84f96b360d05984b</p></div><p>Or you could recall that the … operator selects all commits
contained reachable from either one reference or the other but not
-both: so</p><div class="literallayout"><p>$ git log origin...master</p></div><p>will return no commits when the two branches are equal.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id274712"></a>Find first tagged version including a given fix</h3></div></div></div><p>Suppose you know that the commit e05db0fd fixed a certain problem.
+both: so</p><div class="literallayout"><p>$ git log origin...master</p></div><p>will return no commits when the two branches are equal.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="finding-tagged-descendants"></a>Find first tagged version including a given fix</h3></div></div></div><p>Suppose you know that the commit e05db0fd fixed a certain problem.
You'd like to find the earliest tagged release that contains that
fix.</p><p>Of course, there may be more than one answer—if the history branched
after commit e05db0fd, then there could be multiple "earliest" tagged
   ! [v1.5.0-rc2] GIT v1.5.0-rc2<br>
...</p></div><p>then search for a line that looks like</p><div class="literallayout"><p>+ ++ [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if<br>
available</p></div><p>Which shows that e05db0fd is reachable from itself, from v1.5.0-rc1, and
-from v1.5.0-rc2, but not from v1.5.0-rc0.</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id274876"></a>Chapter 4. Developing with git</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id274882">Telling git your name</a></span></dt><dt><span class="section"><a href="#id274914">Creating a new repository</a></span></dt><dt><span class="section"><a href="#how-to-make-a-commit">How to make a commit</a></span></dt><dt><span class="section"><a href="#id275141">Creating good commit messages</a></span></dt><dt><span class="section"><a href="#id275157">How to merge</a></span></dt><dt><span class="section"><a href="#resolving-a-merge">Resolving a merge</a></span></dt><dd><dl><dt><span class="section"><a href="#id275294">Getting conflict-resolution help during a merge</a></span></dt></dl></dd><dt><span class="section"><a href="#undoing-a-merge">Undoing a merge</a></span></dt><dt><span class="section"><a href="#id275503">Fast-forward merges</a></span></dt><dt><span class="section"><a href="#id275531">Fixing mistakes</a></span></dt><dd><dl><dt><span class="section"><a href="#id275584">Fixing a mistake with a new commit</a></span></dt><dt><span class="section"><a href="#fixing-a-mistake-by-editing-history">Fixing a mistake by editing history</a></span></dt><dt><span class="section"><a href="#id275717">Checking out an old version of a file</a></span></dt></dl></dd><dt><span class="section"><a href="#id275775">Ensuring good performance</a></span></dt><dt><span class="section"><a href="#id275813">Ensuring reliability</a></span></dt><dd><dl><dt><span class="section"><a href="#id275818">Checking the repository for corruption</a></span></dt><dt><span class="section"><a href="#id275893">Recovering lost changes</a></span></dt></dl></dd></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274882"></a>Telling git your name</h2></div></div></div><p>Before creating any commits, you should introduce yourself to git. The
-easiest way to do so is:</p><div class="literallayout"><p>$ cat >~/.gitconfig <<\EOF<br>
-[user]<br>
+from v1.5.0-rc2, but not from v1.5.0-rc0.</p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="Developing-with-git"></a>Chapter 4. Developing with git</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#telling-git-your-name">Telling git your name</a></span></dt><dt><span class="section"><a href="#creating-a-new-repository">Creating a new repository</a></span></dt><dt><span class="section"><a href="#how-to-make-a-commit">How to make a commit</a></span></dt><dt><span class="section"><a href="#creating-good-commit-messages">Creating good commit messages</a></span></dt><dt><span class="section"><a href="#how-to-merge">How to merge</a></span></dt><dt><span class="section"><a href="#resolving-a-merge">Resolving a merge</a></span></dt><dd><dl><dt><span class="section"><a href="#conflict-resolution">Getting conflict-resolution help during a merge</a></span></dt></dl></dd><dt><span class="section"><a href="#undoing-a-merge">Undoing a merge</a></span></dt><dt><span class="section"><a href="#fast-forwards">Fast-forward merges</a></span></dt><dt><span class="section"><a href="#fixing-mistakes">Fixing mistakes</a></span></dt><dd><dl><dt><span class="section"><a href="#reverting-a-commit">Fixing a mistake with a new commit</a></span></dt><dt><span class="section"><a href="#fixing-a-mistake-by-editing-history">Fixing a mistake by editing history</a></span></dt><dt><span class="section"><a href="#checkout-of-path">Checking out an old version of a file</a></span></dt></dl></dd><dt><span class="section"><a href="#ensuring-good-performance">Ensuring good performance</a></span></dt><dt><span class="section"><a href="#ensuring-reliability">Ensuring reliability</a></span></dt><dd><dl><dt><span class="section"><a href="#checking-for-corruption">Checking the repository for corruption</a></span></dt><dt><span class="section"><a href="#recovering-lost-changes">Recovering lost changes</a></span></dt></dl></dd></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="telling-git-your-name"></a>Telling git your name</h2></div></div></div><p>Before creating any commits, you should introduce yourself to git. The
+easiest way to do so is to make sure the following lines appear in a
+file named .gitconfig in your home directory:</p><div class="literallayout"><p>[user]<br>
        name = Your Name Comes Here<br>
-        email = you@yourdomain.example.com<br>
-EOF</p></div><p>(See the "CONFIGURATION FILE" section of <a href="git-config.html" target="_top">git-config(1)</a> for
-details on the configuration file.)</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id274914"></a>Creating a new repository</h2></div></div></div><p>Creating a new repository from scratch is very easy:</p><div class="literallayout"><p>$ mkdir project<br>
+        email = you@yourdomain.example.com</p></div><p>(See the "CONFIGURATION FILE" section of <a href="git-config.html" target="_top">git-config(1)</a> for
+details on the configuration file.)</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="creating-a-new-repository"></a>Creating a new repository</h2></div></div></div><p>Creating a new repository from scratch is very easy:</p><div class="literallayout"><p>$ mkdir project<br>
$ cd project<br>
$ git init</p></div><p>If you have some initial content (say, a tarball):</p><div class="literallayout"><p>$ tar -xzvf project.tar.gz<br>
$ cd project<br>
$ git diff          # difference between the index file and your<br>
                    # working directory; changes that would not<br>
                    # be included if you ran "commit" now.<br>
-$ git status        # a brief per-file summary of the above.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275141"></a>Creating good commit messages</h2></div></div></div><p>Though not required, it's a good idea to begin the commit message
+$ git diff HEAD     # difference between HEAD and working tree; what<br>
+                    # would be committed if you ran "commit -a" now.<br>
+$ git status        # a brief per-file summary of the above.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="creating-good-commit-messages"></a>Creating good commit messages</h2></div></div></div><p>Though not required, it's a good idea to begin the commit message
with a single short (less than 50 character) line summarizing the
change, followed by a blank line and then a more thorough
description. Tools that turn commits into email, for example, use
the first line on the Subject line and the rest of the commit in the
-body.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275157"></a>How to merge</h2></div></div></div><p>You can rejoin two diverging branches of development using
+body.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="how-to-merge"></a>How to merge</h2></div></div></div><p>You can rejoin two diverging branches of development using
<a href="git-merge.html" target="_top">git-merge(1)</a>:</p><div class="literallayout"><p>$ git merge branchname</p></div><p>merges the development in the branch "branchname" into the current
branch. If there are conflicts—for example, if the same file is
modified in two different ways in the remote branch and the local
with the contents and run git commit, as you normally would when
creating a new file.</p><p>If you examine the resulting commit using gitk, you will see that it
has two parents, one pointing to the top of the current branch, and
-one to the top of the other branch.</p><p>In more detail:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="resolving-a-merge"></a>Resolving a merge</h2></div></div></div><p>When a merge isn't resolved automatically, git leaves the index and
+one to the top of the other branch.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="resolving-a-merge"></a>Resolving a merge</h2></div></div></div><p>When a merge isn't resolved automatically, git leaves the index and
the working tree in a special state that gives you all the
information you need to help resolve the merge.</p><p>Files with conflicts are marked specially in the index, so until you
resolve the problem and update the index, <a href="git-commit.html" target="_top">git-commit(1)</a> will
some information about the merge. Normally you can just use this
default message unchanged, but you may add additional commentary of
your own if desired.</p><p>The above is all you need to know to resolve a simple merge. But git
-also provides more information to help resolve conflicts:</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id275294"></a>Getting conflict-resolution help during a merge</h3></div></div></div><p>All of the changes that git was able to merge automatically are
+also provides more information to help resolve conflicts:</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="conflict-resolution"></a>Getting conflict-resolution help during a merge</h3></div></div></div><p>All of the changes that git was able to merge automatically are
already added to the index file, so <a href="git-diff.html" target="_top">git-diff(1)</a> shows only
the conflicts. It uses an unusual syntax:</p><div class="literallayout"><p>$ git diff<br>
diff --cc file.txt<br>
$ git diff --theirs file.txt    # same as the above.</p></div><p>The <a href="git-log.html" target="_top">git-log(1)</a> and gitk[1] commands also provide special help
for merges:</p><div class="literallayout"><p>$ git log --merge<br>
$ gitk --merge</p></div><p>These will display all commits which exist only on HEAD or on
-MERGE_HEAD, and which touch an unmerged file.</p><p>Each time you resolve the conflicts in a file and update the index:</p><div class="literallayout"><p>$ git add file.txt</p></div><p>the different stages of that file will be "collapsed", after which
+MERGE_HEAD, and which touch an unmerged file.</p><p>You may also use gitlink:git-mergetool, which lets you merge the
+unmerged files using external tools such as emacs or kdiff3.</p><p>Each time you resolve the conflicts in a file and update the index:</p><div class="literallayout"><p>$ git add file.txt</p></div><p>the different stages of that file will be "collapsed", after which
git-diff will (by default) no longer show diffs for that file.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="undoing-a-merge"></a>Undoing a merge</h2></div></div></div><p>If you get stuck and decide to just give up and throw the whole mess
away, you can always return to the pre-merge state with</p><div class="literallayout"><p>$ git reset --hard HEAD</p></div><p>Or, if you've already commited the merge that you want to throw away,</p><div class="literallayout"><p>$ git reset --hard ORIG_HEAD</p></div><p>However, this last command can be dangerous in some cases—never
throw away a commit you have already committed if that commit may
itself have been merged into another branch, as doing so may confuse
-further merges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275503"></a>Fast-forward merges</h2></div></div></div><p>There is one special case not mentioned above, which is treated
+further merges.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fast-forwards"></a>Fast-forward merges</h2></div></div></div><p>There is one special case not mentioned above, which is treated
differently. Normally, a merge results in a merge commit, with two
parents, one pointing at each of the two lines of development that
-were merged.</p><p>However, if one of the two lines of development is completely
-contained within the other—so every commit present in the one is
-already contained in the other—then git just performs a
-<a href="#fast-forwards" title="Understanding git history: fast-forwards">fast forward</a>; the head of the current branch is
-moved forward to point at the head of the merged-in branch, without
-any new commits being created.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275531"></a>Fixing mistakes</h2></div></div></div><p>If you've messed up the working tree, but haven't yet committed your
+were merged.</p><p>However, if the current branch is a descendant of the other—so every
+commit present in the one is already contained in the other—then git
+just performs a "fast forward"; the head of the current branch is moved
+forward to point at the head of the merged-in branch, without any new
+commits being created.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fixing-mistakes"></a>Fixing mistakes</h2></div></div></div><p>If you've messed up the working tree, but haven't yet committed your
mistake, you can return the entire working tree to the last committed
state with</p><div class="literallayout"><p>$ git reset --hard HEAD</p></div><p>If you make a commit that you later wish you hadn't, there are two
fundamentally different ways to fix the problem:</p><div class="orderedlist"><ol type="1"><li>
git does not normally expect the "history" of a project to
change, and cannot correctly perform repeated merges from
a branch that has had its history changed.
-</li></ol></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id275584"></a>Fixing a mistake with a new commit</h3></div></div></div><p>Creating a new commit that reverts an earlier change is very easy;
+</li></ol></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="reverting-a-commit"></a>Fixing a mistake with a new commit</h3></div></div></div><p>Creating a new commit that reverts an earlier change is very easy;
just pass the <a href="git-revert.html" target="_top">git-revert(1)</a> command a reference to the bad
commit; for example, to revert the most recent commit:</p><div class="literallayout"><p>$ git revert HEAD</p></div><p>This will create a new commit which undoes the change in HEAD. You
will be given a chance to edit the commit message for the new commit.</p><p>You can also revert an earlier change, for example, the next-to-last:</p><div class="literallayout"><p>$ git revert HEAD^</p></div><p>In this case git will attempt to undo the old change while leaving
been merged into another branch; use <a href="git-revert.html" target="_top">git-revert(1)</a> instead in
that case.</p><p>It is also possible to edit commits further back in the history, but
this is an advanced topic to be left for
-<a href="#cleaning-up-history" title="Chapter 6. Rewriting history and maintaining patch series">another chapter</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id275717"></a>Checking out an old version of a file</h3></div></div></div><p>In the process of undoing a previous bad change, you may find it
+<a href="#cleaning-up-history" title="Chapter 6. Rewriting history and maintaining patch series">another chapter</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="checkout-of-path"></a>Checking out an old version of a file</h3></div></div></div><p>In the process of undoing a previous bad change, you may find it
useful to check out an older version of a particular file using
<a href="git-checkout.html" target="_top">git-checkout(1)</a>. We've used git checkout before to switch
branches, but it has quite different behavior if it is given a path
name: the command</p><div class="literallayout"><p>$ git checkout HEAD^ path/to/file</p></div><p>replaces path/to/file by the contents it had in the commit HEAD^, and
also updates the index to match. It does not change branches.</p><p>If you just want to look at an old version of the file, without
modifying the working directory, you can do that with
-<a href="git-show.html" target="_top">git-show(1)</a>:</p><div class="literallayout"><p>$ git show HEAD^:path/to/file</p></div><p>which will display the given version of the file.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275775"></a>Ensuring good performance</h2></div></div></div><p>On large repositories, git depends on compression to keep the history
+<a href="git-show.html" target="_top">git-show(1)</a>:</p><div class="literallayout"><p>$ git show HEAD^:path/to/file</p></div><p>which will display the given version of the file.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ensuring-good-performance"></a>Ensuring good performance</h2></div></div></div><p>On large repositories, git depends on compression to keep the history
information from taking up to much space on disk or in memory.</p><p>This compression is not performed automatically. Therefore you
should occasionally run <a href="git-gc.html" target="_top">git-gc(1)</a>:</p><div class="literallayout"><p>$ git gc</p></div><p>to recompress the archive. This can be very time-consuming, so
-you may prefer to run git-gc when you are not doing other work.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id275813"></a>Ensuring reliability</h2></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id275818"></a>Checking the repository for corruption</h3></div></div></div><p>The <a href="git-fsck.html" target="_top">git-fsck(1)</a> command runs a number of self-consistency checks
+you may prefer to run git-gc when you are not doing other work.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ensuring-reliability"></a>Ensuring reliability</h2></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="checking-for-corruption"></a>Checking the repository for corruption</h3></div></div></div><p>The <a href="git-fsck.html" target="_top">git-fsck(1)</a> command runs a number of self-consistency checks
on the repository, and reports on any problems. This may take some
time. The most common warning by far is about "dangling" objects:</p><div class="literallayout"><p>$ git fsck<br>
dangling commit 7281251ddd2a61e38657c827739c57015671a6b3<br>
dangling commit 8e4bec7f2ddaa268bef999853c25755452100f8e<br>
dangling tree d50bb86186bf27b681d25af89d3b5b68382e4085<br>
dangling tree b24c2473f1fd3d91352a624795be026d64c8841f<br>
-...</p></div><p>Dangling objects are objects that are harmless, but also unnecessary;
-you can remove them at any time with <a href="git-prune.html" target="_top">git-prune(1)</a> or the —prune
+...</p></div><p>Dangling objects are not a problem. At worst they may take up a little
+extra disk space. They can sometimes provide a last-resort method of
+recovery lost work—see <a href="#dangling-objects" title="Dangling objects">the section called “Dangling objects”</a> for details. However, if
+you want, you may remove them with <a href="git-prune.html" target="_top">git-prune(1)</a> or the —prune
option to <a href="git-gc.html" target="_top">git-gc(1)</a>:</p><div class="literallayout"><p>$ git gc --prune</p></div><p>This may be time-consuming. Unlike most other git operations (including
git-gc when run without any options), it is not safe to prune while
-other git operations are in progress in the same repository.</p><p>For more about dangling objects, see <a href="#dangling-objects" title="Dangling objects">the section called “Dangling objects”</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id275893"></a>Recovering lost changes</h3></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id275899"></a>Reflogs</h4></div></div></div><p>Say you modify a branch with <a href="git-reset.html" target="_top">git-reset(1)</a> —hard, and then
+other git operations are in progress in the same repository.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="recovering-lost-changes"></a>Recovering lost changes</h3></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="reflogs"></a>Reflogs</h4></div></div></div><p>Say you modify a branch with <a href="git-reset.html" target="_top">git-reset(1)</a> —hard, and then
realize that the branch was the only reference you had to that point in
history.</p><p>Fortunately, git also keeps a log, called a "reflog", of all the
previous values of each branch. So in this case you can still find the
not just with git log. Some other examples:</p><div class="literallayout"><p>$ git show master@{2}           # See where the branch pointed 2,<br>
$ git show master@{3}           # 3, ... changes ago.<br>
$ gitk master@{yesterday}       # See where it pointed yesterday,<br>
-$ gitk master@{"1 week ago"}    # ... or last week</p></div><p>The reflogs are kept by default for 30 days, after which they may be
+$ gitk master@{"1 week ago"}    # ... or last week<br>
+$ git log --walk-reflogs master # show reflog entries for master</p></div><p>A separate reflog is kept for the HEAD, so</p><div class="literallayout"><p>$ git show HEAD@{"1 week ago"}</p></div><p>will show what HEAD pointed to one week ago, not what the current branch
+pointed to one week ago. This allows you to see the history of what
+you've checked out.</p><p>The reflogs are kept by default for 30 days, after which they may be
pruned. See <a href="git-reflog.html" target="_top">git-reflog(1)</a> and <a href="git-gc.html" target="_top">git-gc(1)</a> to learn
how to control this pruning, and see the "SPECIFYING REVISIONS"
section of <a href="git-rev-parse.html" target="_top">git-rev-parse(1)</a> for details.</p><p>Note that the reflog history is very different from normal git history.
While normal history is shared by every repository that works on the
same project, the reflog history is not shared: it tells you only about
-how the branches in your local repository have changed over time.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id275977"></a>Examining dangling objects</h4></div></div></div><p>In some situations the reflog may not be able to save you. For
-example, suppose you delete a branch, then realize you need the history
-it contained. The reflog is also deleted; however, if you have not
-yet pruned the repository, then you may still be able to find
-the lost commits; run git-fsck and watch for output that mentions
-"dangling commits":</p><div class="literallayout"><p>$ git fsck<br>
+how the branches in your local repository have changed over time.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="dangling-object-recovery"></a>Examining dangling objects</h4></div></div></div><p>In some situations the reflog may not be able to save you. For example,
+suppose you delete a branch, then realize you need the history it
+contained. The reflog is also deleted; however, if you have not yet
+pruned the repository, then you may still be able to find the lost
+commits in the dangling objects that git-fsck reports. See
+<a href="#dangling-objects" title="Dangling objects">the section called “Dangling objects”</a> for the details.</p><div class="literallayout"><p>$ git fsck<br>
dangling commit 7281251ddd2a61e38657c827739c57015671a6b3<br>
dangling commit 2706a059f258c6b245f298dc4ff2ccd30ec21a63<br>
dangling commit 13472b7c4b80851a1bc551779171dcb03655e9b5<br>
(And notice that it might not be just one commit: we only report the
"tip of the line" as being dangling, but there might be a whole deep
and complex commit history that was dropped.)</p><p>If you decide you want the history back, you can always create a new
-reference pointing to it, for example, a new branch:</p><div class="literallayout"><p>$ git branch recovered-branch 7281251ddd</p></div></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id232226"></a>Chapter 5. Sharing development with others</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#getting-updates-with-git-pull">Getting updates with git pull</a></span></dt><dt><span class="section"><a href="#id276243">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#id276292">Importing patches to a project</a></span></dt><dt><span class="section"><a href="#setting-up-a-public-repository">Setting up a public repository</a></span></dt><dt><span class="section"><a href="#exporting-via-http">Exporting a git repository via http</a></span></dt><dt><span class="section"><a href="#exporting-via-git">Exporting a git repository via the git protocol</a></span></dt><dt><span class="section"><a href="#pushing-changes-to-a-public-repository">Pushing changes to a public repository</a></span></dt><dt><span class="section"><a href="#id276705">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#id276724">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#id276737">Examples</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="getting-updates-with-git-pull"></a>Getting updates with git pull</h2></div></div></div><p>After you clone a repository and make a few changes of your own, you
+reference pointing to it, for example, a new branch:</p><div class="literallayout"><p>$ git branch recovered-branch 7281251ddd</p></div><p>Other types of dangling objects (blobs and trees) are also possible, and
+dangling objects can arise in other situations.</p></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sharing-development"></a>Chapter 5. Sharing development with others</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#getting-updates-with-git-pull">Getting updates with git pull</a></span></dt><dt><span class="section"><a href="#submitting-patches">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#importing-patches">Importing patches to a project</a></span></dt><dt><span class="section"><a href="#setting-up-a-public-repository">Setting up a public repository</a></span></dt><dt><span class="section"><a href="#exporting-via-http">Exporting a git repository via http</a></span></dt><dt><span class="section"><a href="#exporting-via-git">Exporting a git repository via the git protocol</a></span></dt><dt><span class="section"><a href="#pushing-changes-to-a-public-repository">Pushing changes to a public repository</a></span></dt><dt><span class="section"><a href="#setting-up-a-shared-repository">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#setting-up-gitweb">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#sharing-development-examples">Examples</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="getting-updates-with-git-pull"></a>Getting updates with git pull</h2></div></div></div><p>After you clone a repository and make a few changes of your own, you
may wish to check the original repository for updates and merge them
into your own work.</p><p>We have already seen <a href="#Updating-a-repository-with-git-fetch" title="Updating a repository with git fetch">how to keep remote tracking branches up to date</a> with <a href="git-fetch.html" target="_top">git-fetch(1)</a>,
and how to merge two branches. So you can merge in changes from the
$ git merge origin/master</p></div><p>However, the <a href="git-pull.html" target="_top">git-pull(1)</a> command provides a way to do this in
one step:</p><div class="literallayout"><p>$ git pull origin master</p></div><p>In fact, "origin" is normally the default repository to pull from,
and the default branch is normally the HEAD of the remote repository,
-so often you can accomplish the above with just</p><div class="literallayout"><p>$ git pull</p></div><p>See the descriptions of the branch.<name>.remote and
-branch.<name>.merge options in <a href="git-config.html" target="_top">git-config(1)</a> to learn
-how to control these defaults depending on the current branch.</p><p>In addition to saving you keystrokes, "git pull" also helps you by
+so often you can accomplish the above with just</p><div class="literallayout"><p>$ git pull</p></div><p>See the descriptions of the branch.<name>.remote and branch.<name>.merge
+options in <a href="git-config.html" target="_top">git-config(1)</a> to learn how to control these defaults
+depending on the current branch. Also note that the —track option to
+<a href="git-branch.html" target="_top">git-branch(1)</a> and <a href="git-checkout.html" target="_top">git-checkout(1)</a> can be used to
+automatically set the default remote branch to pull from at the time
+that a branch is created:</p><div class="literallayout"><p>$ git checkout --track -b origin/maint maint</p></div><p>In addition to saving you keystrokes, "git pull" also helps you by
producing a default commit message documenting the branch and
repository that you pulled from.</p><p>(But note that no such commit will be created in the case of a
-<a href="#fast-forwards" title="Understanding git history: fast-forwards">fast forward</a>; instead, your branch will just be
+<a href="#fast-forwards" title="Fast-forward merges">fast forward</a>; instead, your branch will just be
updated to point to the latest commit from the upstream branch.)</p><p>The git-pull command can also be given "." as the "remote" repository,
in which case it just merges in a branch from the current repository; so
the commands</p><div class="literallayout"><p>$ git pull . branch<br>
-$ git merge branch</p></div><p>are roughly equivalent. The former is actually very commonly used.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276243"></a>Submitting patches to a project</h2></div></div></div><p>If you just have a few changes, the simplest way to submit them may
+$ git merge branch</p></div><p>are roughly equivalent. The former is actually very commonly used.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="submitting-patches"></a>Submitting patches to a project</h2></div></div></div><p>If you just have a few changes, the simplest way to submit them may
just be to send them as patches in email:</p><p>First, use <a href="git-format-patch.html" target="_top">git-format-patch(1)</a>; for example:</p><div class="literallayout"><p>$ git format-patch origin</p></div><p>will produce a numbered series of files in the current directory, one
for each patch in the current branch but not in origin/HEAD.</p><p>You can then import these into your mail client and send them by
hand. However, if you have a lot to send at once, you may prefer to
use the <a href="git-send-email.html" target="_top">git-send-email(1)</a> script to automate the process.
Consult the mailing list for your project first to determine how they
-prefer such patches be handled.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276292"></a>Importing patches to a project</h2></div></div></div><p>Git also provides a tool called <a href="git-am.html" target="_top">git-am(1)</a> (am stands for
+prefer such patches be handled.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="importing-patches"></a>Importing patches to a project</h2></div></div></div><p>Git also provides a tool called <a href="git-am.html" target="_top">git-am(1)</a> (am stands for
"apply mailbox"), for importing such an emailed series of patches.
Just save all of the patch-containing messages, in order, into a
single mailbox file, say "patches.mbox", then run</p><div class="literallayout"><p>$ git am -3 patches.mbox</p></div><p>Git will apply each patch in order; if any conflicts are found, it
| |
| they push V
their public repo <------------------- their repo</pre><p>Now, assume your personal repository is in the directory ~/proj. We
-first create a new clone of the repository:</p><div class="literallayout"><p>$ git clone --bare proj-clone.git</p></div><p>The resulting directory proj-clone.git will contains a "bare" git
+first create a new clone of the repository:</p><div class="literallayout"><p>$ git clone --bare proj.git</p></div><p>The resulting directory proj.git will contains a "bare" git
repository—it is just the contents of the ".git" directory, without
-a checked-out copy of a working directory.</p><p>Next, copy proj-clone.git to the server where you plan to host the
+a checked-out copy of a working directory.</p><p>Next, copy proj.git to the server where you plan to host the
public repository. You can use scp, rsync, or whatever is most
convenient.</p><p>If somebody else maintains the public server, they may already have
set up a git service for you, and you may skip to the section
a directory that is exported by the web server, and make some
adjustments to give web clients some extra information they need:</p><div class="literallayout"><p>$ mv proj.git /home/you/public_html/proj.git<br>
$ cd proj.git<br>
-$ git update-server-info<br>
+$ git --bare update-server-info<br>
$ chmod a+x hooks/post-update</p></div><p>(For an explanation of the last two lines, see
<a href="git-update-server-info.html" target="_top">git-update-server-info(1)</a>, and the documentation
<a href="hooks.txt" target="_top">Hooks used by git</a>.)</p><p>Advertise the url of proj.git. Anybody else should then be able to
latest changes created in your private repository.</p><p>The simplest way to do this is using <a href="git-push.html" target="_top">git-push(1)</a> and ssh; to
update the remote branch named "master" with the latest state of your
branch named "master", run</p><div class="literallayout"><p>$ git push ssh://yourserver.com/~you/proj.git master:master</p></div><p>or just</p><div class="literallayout"><p>$ git push ssh://yourserver.com/~you/proj.git master</p></div><p>As with git-fetch, git-push will complain if this does not result in
-a <a href="#fast-forwards" title="Understanding git history: fast-forwards">fast forward</a>. Normally this is a sign of
+a <a href="#fast-forwards" title="Fast-forward merges">fast forward</a>. Normally this is a sign of
something wrong. However, if you are sure you know what you're
doing, you may force git-push to perform the update anyway by
proceeding the branch name by a plus sign:</p><div class="literallayout"><p>$ git push ssh://yourserver.com/~you/proj.git +master</p></div><p>As with git-fetch, you may also set up configuration options to
-save typing; so, for example, after</p><div class="literallayout"><p>$ cat >.git/config <<EOF<br>
+save typing; so, for example, after</p><div class="literallayout"><p>$ cat >>.git/config <<EOF<br>
[remote "public-repo"]<br>
        url = ssh://yourserver.com/~you/proj.git<br>
EOF</p></div><p>you should be able to perform the above push with just</p><div class="literallayout"><p>$ git push public-repo master</p></div><p>See the explanations of the remote.<name>.url, branch.<name>.remote,
and remote.<name>.push options in <a href="git-config.html" target="_top">git-config(1)</a> for
-details.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276705"></a>Setting up a shared repository</h2></div></div></div><p>Another way to collaborate is by using a model similar to that
+details.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="setting-up-a-shared-repository"></a>Setting up a shared repository</h2></div></div></div><p>Another way to collaborate is by using a model similar to that
commonly used in CVS, where several developers with special rights
all push to and pull from a single shared repository. See
<a href="cvs-migration.txt" target="_top">git for CVS users</a> for instructions on how to
-set this up.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276724"></a>Allow web browsing of a repository</h2></div></div></div><p>The gitweb cgi script provides users an easy way to browse your
+set this up.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="setting-up-gitweb"></a>Allow web browsing of a repository</h2></div></div></div><p>The gitweb cgi script provides users an easy way to browse your
project's files and history without having to install git; see the file
-gitweb/INSTALL in the git source tree for instructions on setting it up.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276737"></a>Examples</h2></div></div></div><p>TODO: topic branches, typical roles as in everyday.txt, ?</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="cleaning-up-history"></a>Chapter 6. Rewriting history and maintaining patch series</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id276769">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#id276844">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#id276974">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#id277071">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#id277131">Other tools</a></span></dt><dt><span class="section"><a href="#id277144">Problems with rewriting history</a></span></dt></dl></div><p>Normally commits are only added to a project, never taken away or
+gitweb/INSTALL in the git source tree for instructions on setting it up.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sharing-development-examples"></a>Examples</h2></div></div></div><p>TODO: topic branches, typical roles as in everyday.txt, ?</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="cleaning-up-history"></a>Chapter 6. Rewriting history and maintaining patch series</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#patch-series">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#using-git-rebase">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#modifying-one-commit">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#reordering-patch-series">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#patch-series-tools">Other tools</a></span></dt><dt><span class="section"><a href="#problems-with-rewriting-history">Problems with rewriting history</a></span></dt></dl></div><p>Normally commits are only added to a project, never taken away or
replaced. Git is designed with this assumption, and violating it will
cause git's merge machinery (for example) to do the wrong thing.</p><p>However, there is a situation in which it can be useful to violate this
-assumption.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276769"></a>Creating the perfect patch series</h2></div></div></div><p>Suppose you are a contributor to a large project, and you want to add a
+assumption.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="patch-series"></a>Creating the perfect patch series</h2></div></div></div><p>Suppose you are a contributor to a large project, and you want to add a
complicated feature, and to present it to the other developers in a way
that makes it easy for them to read your changes, verify that they are
correct, and understand why you made each change.</p><p>If you present all of your changes as a single patch (or commit), they
(probably much messier!) development process did.
</li></ol></div><p>We will introduce some tools that can help you do this, explain how to
use them, and then explain some of the problems that can arise because
-you are rewriting history.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276844"></a>Keeping a patch series up to date using git-rebase</h2></div></div></div><p>Suppose that you create a branch "mywork" on a remote-tracking branch
+you are rewriting history.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="using-git-rebase"></a>Keeping a patch series up to date using git-rebase</h2></div></div></div><p>Suppose that you create a branch "mywork" on a remote-tracking branch
"origin", and create some commits on top of it:</p><div class="literallayout"><p>$ git checkout -b mywork origin<br>
$ vi file.txt<br>
$ git commit<br>
and allow you to fix the conflicts; after fixing conflicts, use "git
add" to update the index with those contents, and then, instead of
running git-commit, just run</p><div class="literallayout"><p>$ git rebase --continue</p></div><p>and git will continue applying the rest of the patches.</p><p>At any point you may use the —abort option to abort this process and
-return mywork to the state it had before you started the rebase:</p><div class="literallayout"><p>$ git rebase --abort</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id276974"></a>Modifying a single commit</h2></div></div></div><p>We saw in <a href="#fixing-a-mistake-by-editing-history" title="Fixing a mistake by editing history">the section called “Fixing a mistake by editing history”</a> that you can replace the
+return mywork to the state it had before you started the rebase:</p><div class="literallayout"><p>$ git rebase --abort</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="modifying-one-commit"></a>Modifying a single commit</h2></div></div></div><p>We saw in <a href="#fixing-a-mistake-by-editing-history" title="Fixing a mistake by editing history">the section called “Fixing a mistake by editing history”</a> that you can replace the
most recent commit using</p><div class="literallayout"><p>$ git commit --amend</p></div><p>which will replace the old commit by a new commit incorporating your
changes, giving you a chance to edit the old commit message first.</p><p>You can also use a combination of this and <a href="git-rebase.html" target="_top">git-rebase(1)</a> to edit
commits further back in your history. First, tag the problematic commit with</p><div class="literallayout"><p>$ git tag bad mywork~5</p></div><p>(Either gitk or git-log may be useful for finding the commit.)</p><p>Then check out that commit, edit it, and rebase the rest of the series
patches on mywork reapplied on top of your modified commit. You can
then clean up with</p><div class="literallayout"><p>$ git tag -d bad</p></div><p>Note that the immutable nature of git history means that you haven't really
"modified" existing commits; instead, you have replaced the old commits with
-new commits having new object names.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277071"></a>Reordering or selecting from a patch series</h2></div></div></div><p>Given one existing commit, the <a href="git-cherry-pick.html" target="_top">git-cherry-pick(1)</a> command
+new commits having new object names.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="reordering-patch-series"></a>Reordering or selecting from a patch series</h2></div></div></div><p>Given one existing commit, the <a href="git-cherry-pick.html" target="_top">git-cherry-pick(1)</a> command
allows you to apply the change introduced by that commit and create a
new commit that records it. So, for example, if "mywork" points to a
series of patches on top of "origin", you might do something like:</p><div class="literallayout"><p>$ git checkout -b mywork-new origin<br>
—amend.</p><p>Another technique is to use git-format-patch to create a series of
patches, then reset the state to before the patches:</p><div class="literallayout"><p>$ git format-patch origin<br>
$ git reset --hard origin</p></div><p>Then modify, reorder, or eliminate patches as preferred before applying
-them again with <a href="git-am.html" target="_top">git-am(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277131"></a>Other tools</h2></div></div></div><p>There are numerous other tools, such as stgit, which exist for the
+them again with <a href="git-am.html" target="_top">git-am(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="patch-series-tools"></a>Other tools</h2></div></div></div><p>There are numerous other tools, such as stgit, which exist for the
purpose of maintaining a patch series. These are outside of the scope of
-this manual.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277144"></a>Problems with rewriting history</h2></div></div></div><p>The primary problem with rewriting the history of a branch has to do
+this manual.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="problems-with-rewriting-history"></a>Problems with rewriting history</h2></div></div></div><p>The primary problem with rewriting the history of a branch has to do
with merging. Suppose somebody fetches your branch and merges it into
their branch, with a result something like this:</p><pre class="literallayout"> o--o--O--o--o--o <-- origin
\ \
and it may be useful for others to be able to fetch those branches in
order to examine or test them, but they should not attempt to pull such
branches into their own work.</p><p>For true distributed development that supports proper merging,
-published branches should never be rewritten.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id277215"></a>Chapter 7. Advanced branch management</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id277220">Fetching individual branches</a></span></dt><dt><span class="section"><a href="#fast-forwards">Understanding git history: fast-forwards</a></span></dt><dt><span class="section"><a href="#id277341">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#id277368">Configuring remote branches</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277220"></a>Fetching individual branches</h2></div></div></div><p>Instead of using <a href="git-remote.html" target="_top">git-remote(1)</a>, you can also choose just
+published branches should never be rewritten.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="advanced-branch-management"></a>Chapter 7. Advanced branch management</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#fetching-individual-branches">Fetching individual branches</a></span></dt><dt><span class="section"><a href="#fetch-fast-forwards">git fetch and fast-forwards</a></span></dt><dt><span class="section"><a href="#forcing-fetch">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#remote-branch-configuration">Configuring remote branches</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fetching-individual-branches"></a>Fetching individual branches</h2></div></div></div><p>Instead of using <a href="git-remote.html" target="_top">git-remote(1)</a>, you can also choose just
to update one branch at a time, and to store it locally under an
arbitrary name:</p><div class="literallayout"><p>$ git fetch origin todo:my-todo-work</p></div><p>The first argument, "origin", just tells git to fetch from the
repository you originally cloned from. The second argument tells git
store it locally under the name refs/heads/my-todo-work.</p><p>You can also fetch branches from other repositories; so</p><div class="literallayout"><p>$ git fetch git://example.com/proj.git master:example-master</p></div><p>will create a new branch named "example-master" and store in it the
branch named "master" from the repository at the given URL. If you
already have a branch named example-master, it will attempt to
-"fast-forward" to the commit given by example.com's master branch. So
-next we explain what a fast-forward is:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fast-forwards"></a>Understanding git history: fast-forwards</h2></div></div></div><p>In the previous example, when updating an existing branch, "git
+<a href="#fast-forwards" title="Fast-forward merges">fast-forward</a> to the commit given by example.com's
+master branch. In more detail:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="fetch-fast-forwards"></a>git fetch and fast-forwards</h2></div></div></div><p>In the previous example, when updating an existing branch, "git
fetch" checks to make sure that the most recent commit on the remote
branch is a descendant of the most recent commit on your copy of the
branch before updating your copy of the branch to point at the new
-commit. Git calls this process a "fast forward".</p><p>A fast forward looks something like this:</p><pre class="literallayout"> o--o--o--o <-- old head of the branch
+commit. Git calls this process a <a href="#fast-forwards" title="Fast-forward merges">fast forward</a>.</p><p>A fast forward looks something like this:</p><pre class="literallayout"> o--o--o--o <-- old head of the branch
\
o--o--o <-- new head of the branch</pre><p>In some cases it is possible that the new head will <span class="strong"><strong>not</strong></span> actually be
a descendant of the old head. For example, the developer may have
described in the following section. However, note that in the
situation above this may mean losing the commits labeled "a" and "b",
unless you've already created a reference of your own pointing to
-them.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277341"></a>Forcing git fetch to do non-fast-forward updates</h2></div></div></div><p>If git fetch fails because the new head of a branch is not a
-descendant of the old head, you may force the update with:</p><div class="literallayout"><p>$ git fetch git://example.com/proj.git +master:refs/remotes/example/master</p></div><p>Note the addition of the "+" sign. Be aware that commits that the
-old version of example/master pointed at may be lost, as we saw in
-the previous section.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277368"></a>Configuring remote branches</h2></div></div></div><p>We saw above that "origin" is just a shortcut to refer to the
+them.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="forcing-fetch"></a>Forcing git fetch to do non-fast-forward updates</h2></div></div></div><p>If git fetch fails because the new head of a branch is not a
+descendant of the old head, you may force the update with:</p><div class="literallayout"><p>$ git fetch git://example.com/proj.git +master:refs/remotes/example/master</p></div><p>Note the addition of the "+" sign. Alternatively, you can use the "-f"
+flag to force updates of all the fetched branches, as in:</p><div class="literallayout"><p>$ git fetch -f origin</p></div><p>Be aware that commits that the old version of example/master pointed at
+may be lost, as we saw in the previous section.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="remote-branch-configuration"></a>Configuring remote branches</h2></div></div></div><p>We saw above that "origin" is just a shortcut to refer to the
repository that you originally cloned from. This information is
stored in git configuration variables, which you can see using
<a href="git-config.html" target="_top">git-config(1)</a>:</p><div class="literallayout"><p>$ git config -l<br>
throwing away commits on mybranch.</p><p>Also note that all of the above configuration can be performed by
directly editing the file .git/config instead of using
<a href="git-config.html" target="_top">git-config(1)</a>.</p><p>See <a href="git-config.html" target="_top">git-config(1)</a> for more details on the configuration
-options mentioned above.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="git-internals"></a>Chapter 8. Git internals</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#id277506">The Object Database</a></span></dt><dt><span class="section"><a href="#id277659">Blob Object</a></span></dt><dt><span class="section"><a href="#id277703">Tree Object</a></span></dt><dt><span class="section"><a href="#id277780">Commit Object</a></span></dt><dt><span class="section"><a href="#id277827">Trust</a></span></dt><dt><span class="section"><a href="#id277878">Tag Object</a></span></dt><dt><span class="section"><a href="#id277924">The "index" aka "Current Directory Cache"</a></span></dt><dt><span class="section"><a href="#id277999">The Workflow</a></span></dt><dd><dl><dt><span class="section"><a href="#id278018">working directory -> index</a></span></dt><dt><span class="section"><a href="#id278108">index -> object database</a></span></dt><dt><span class="section"><a href="#id278136">object database -> index</a></span></dt><dt><span class="section"><a href="#id278167">index -> working directory</a></span></dt><dt><span class="section"><a href="#id278230">Tying it all together</a></span></dt></dl></dd><dt><span class="section"><a href="#id278325">Examining the data</a></span></dt><dt><span class="section"><a href="#id278403">Merging multiple trees</a></span></dt><dt><span class="section"><a href="#id278490">Merging multiple trees, continued</a></span></dt><dt><span class="section"><a href="#id278750">How git stores objects efficiently: pack files</a></span></dt><dt><span class="section"><a href="#dangling-objects">Dangling objects</a></span></dt></dl></div><p>Git depends on two fundamental abstractions: the "object database", and
-the "current directory cache" aka "index".</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277506"></a>The Object Database</h2></div></div></div><p>The object database is literally just a content-addressable collection
+options mentioned above.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="git-internals"></a>Chapter 8. Git internals</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#the-object-database">The Object Database</a></span></dt><dt><span class="section"><a href="#blob-object">Blob Object</a></span></dt><dt><span class="section"><a href="#tree-object">Tree Object</a></span></dt><dt><span class="section"><a href="#commit-object">Commit Object</a></span></dt><dt><span class="section"><a href="#trust">Trust</a></span></dt><dt><span class="section"><a href="#tag-object">Tag Object</a></span></dt><dt><span class="section"><a href="#the-index">The "index" aka "Current Directory Cache"</a></span></dt><dt><span class="section"><a href="#the-workflow">The Workflow</a></span></dt><dd><dl><dt><span class="section"><a href="#working-directory-to-index">working directory -> index</a></span></dt><dt><span class="section"><a href="#index-to-object-database">index -> object database</a></span></dt><dt><span class="section"><a href="#object-database-to-index">object database -> index</a></span></dt><dt><span class="section"><a href="#index-to-working-directory">index -> working directory</a></span></dt><dt><span class="section"><a href="#tying-it-all-together">Tying it all together</a></span></dt></dl></dd><dt><span class="section"><a href="#examining-the-data">Examining the data</a></span></dt><dt><span class="section"><a href="#merging-multiple-trees">Merging multiple trees</a></span></dt><dt><span class="section"><a href="#merging-multiple-trees-2">Merging multiple trees, continued</a></span></dt><dt><span class="section"><a href="#pack-files">How git stores objects efficiently: pack files</a></span></dt><dt><span class="section"><a href="#dangling-objects">Dangling objects</a></span></dt></dl></div><p>Git depends on two fundamental abstractions: the "object database", and
+the "current directory cache" aka "index".</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="the-object-database"></a>The Object Database</h2></div></div></div><p>The object database is literally just a content-addressable collection
of objects. All objects are named by their content, which is
approximated by the SHA1 hash of the object itself. Objects may refer
to other objects (by referencing their SHA1 hash), and so you can
-build up a hierarchy of objects.</p><p>All objects have a statically determined "type" aka "tag", which is
+build up a hierarchy of objects.</p><p>All objects have a statically determined "type" which is
determined at object creation time, and which identifies the format of
the object (i.e. how it is used, and how it can refer to other
objects). There are currently four different object types: "blob",
the time of the commit). In addition, a "commit" refers to one or more
"parent" commit objects that describe the history of how we arrived at
that directory hierarchy.</p><p>As a special case, a commit object with no parents is called the "root"
-object, and is the point of an initial project commit. Each project
+commit, and is the point of an initial project commit. Each project
must have at least one root, and while you can tie several different
root objects together into one project by creating a commit object which
has two or more separate roots as its ultimate parents, that's probably
connectivity to other objects verified. This is generally done with
the <code class="literal">git-fsck</code> program, which generates a full dependency graph
of all objects, and verifies their internal consistency (in addition
-to just verifying their superficial consistency through the hash).</p><p>The object types in some more detail:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277659"></a>Blob Object</h2></div></div></div><p>A "blob" object is nothing but a binary blob of data, and doesn't
+to just verifying their superficial consistency through the hash).</p><p>The object types in some more detail:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="blob-object"></a>Blob Object</h2></div></div></div><p>A "blob" object is nothing but a binary blob of data, and doesn't
refer to anything else. There is no signature or any other
verification of the data, so while the object is consistent (it <span class="emphasis"><em>is</em></span>
indexed by its sha1 hash, so the data itself is certainly correct), it
object. The object is totally independent of its location in the
directory tree, and renaming a file does not change the object that
file is associated with in any way.</p><p>A blob is typically created when <a href="git-update-index.html" target="_top">git-update-index(1)</a>
-is run, and its data can be accessed by <a href="git-cat-file.html" target="_top">git-cat-file(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277703"></a>Tree Object</h2></div></div></div><p>The next hierarchical object type is the "tree" object. A tree object
+is run, and its data can be accessed by <a href="git-cat-file.html" target="_top">git-cat-file(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tree-object"></a>Tree Object</h2></div></div></div><p>The next hierarchical object type is the "tree" object. A tree object
is a list of mode/name/blob data, sorted by name. Alternatively, the
mode data may specify a directory mode, in which case instead of
naming a blob, that name is associated with another TREE object.</p><p>Like the "blob" object, a tree object is uniquely determined by the
noticing that the blob stayed the same. However, renames with data
changes need a smarter "diff" implementation.</p><p>A tree is created with <a href="git-write-tree.html" target="_top">git-write-tree(1)</a> and
its data can be accessed by <a href="git-ls-tree.html" target="_top">git-ls-tree(1)</a>.
-Two trees can be compared with <a href="git-diff-tree.html" target="_top">git-diff-tree(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277780"></a>Commit Object</h2></div></div></div><p>The "commit" object is an object that introduces the notion of
+Two trees can be compared with <a href="git-diff-tree.html" target="_top">git-diff-tree(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="commit-object"></a>Commit Object</h2></div></div></div><p>The "commit" object is an object that introduces the notion of
history into the picture. In contrast to the other objects, it
doesn't just describe the physical state of a tree, it describes how
we got there, and why.</p><p>A "commit" is defined by the tree-object that it results in, the
strong signatures at all levels, but there is no reason to believe
that the tree is "good" or that the merge information makes sense.
The parents do not have to actually have any relationship with the
-result, for example.</p><p>Note on commits: unlike real SCM's, commits do not contain
+result, for example.</p><p>Note on commits: unlike some SCM's, commits do not contain
rename information or file mode change information. All of that is
implicit in the trees involved (the result tree, and the result trees
of the parents), and describing that makes no sense in this idiotic
file manager.</p><p>A commit is created with <a href="git-commit-tree.html" target="_top">git-commit-tree(1)</a> and
-its data can be accessed by <a href="git-cat-file.html" target="_top">git-cat-file(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277827"></a>Trust</h2></div></div></div><p>An aside on the notion of "trust". Trust is really outside the scope
+its data can be accessed by <a href="git-cat-file.html" target="_top">git-cat-file(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="trust"></a>Trust</h2></div></div></div><p>An aside on the notion of "trust". Trust is really outside the scope
of "git", but it's worth noting a few things. First off, since
everything is hashed with SHA1, you <span class="emphasis"><em>can</em></span> trust that an object is
intact and has not been messed with by external sources. So the name
commits tells others that they can trust the whole history.</p><p>In other words, you can easily validate a whole archive by just
sending out a single email that tells the people the name (SHA1 hash)
of the top commit, and digitally sign that email using something
-like GPG/PGP.</p><p>To assist in this, git also provides the tag object…</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277878"></a>Tag Object</h2></div></div></div><p>Git provides the "tag" object to simplify creating, managing and
+like GPG/PGP.</p><p>To assist in this, git also provides the tag object…</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tag-object"></a>Tag Object</h2></div></div></div><p>Git provides the "tag" object to simplify creating, managing and
exchanging symbolic and signed tokens. The "tag" object at its
simplest simply symbolically identifies another object by containing
the sha1, type and symbolic name.</p><p>However it can optionally contain additional signature information
verification) has to come from outside.</p><p>A tag is created with <a href="git-mktag.html" target="_top">git-mktag(1)</a>,
its data can be accessed by <a href="git-cat-file.html" target="_top">git-cat-file(1)</a>,
and the signature can be verified by
-<a href="git-verify-tag.html" target="_top">git-verify-tag(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277924"></a>The "index" aka "Current Directory Cache"</h2></div></div></div><p>The index is a simple binary file, which contains an efficient
-representation of a virtual directory content at some random time. It
+<a href="git-verify-tag.html" target="_top">git-verify-tag(1)</a>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="the-index"></a>The "index" aka "Current Directory Cache"</h2></div></div></div><p>The index is a simple binary file, which contains an efficient
+representation of the contents of a virtual directory. It
does so by a simple array that associates a set of names, dates,
permissions and content (aka "blob") objects together. The cache is
always kept ordered by name, and names are unique (with a few very
the index file can have the representation of an intermediate tree that
has not yet been instantiated. So the index can be thought of as a
write-back cache, which can contain dirty information that has not yet
-been written back to the backing store.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id277999"></a>The Workflow</h2></div></div></div><p>Generally, all "git" operations work on the index file. Some operations
+been written back to the backing store.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="the-workflow"></a>The Workflow</h2></div></div></div><p>Generally, all "git" operations work on the index file. Some operations
work <span class="strong"><strong>purely</strong></span> on the index file (showing the current state of the
index), but most operations move data to and from the index file. Either
from the database or from the working directory. Thus there are four
-main combinations:</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278018"></a>working directory -> index</h3></div></div></div><p>You update the index with information from the working directory with
+main combinations:</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="working-directory-to-index"></a>working directory -> index</h3></div></div></div><p>You update the index with information from the working directory with
the <a href="git-update-index.html" target="_top">git-update-index(1)</a> command. You
generally update the index information by just specifying the filename
you want to update, like so:</p><div class="literallayout"><p>$ git-update-index filename</p></div><p>but to avoid common mistakes with filename globbing etc, the command
will refresh the "stat" information of each index to match the current
stat information. It will <span class="emphasis"><em>not</em></span> update the object status itself, and
it will only update the fields that are used to quickly test whether
-an object still matches its old backing store object.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278108"></a>index -> object database</h3></div></div></div><p>You write your current index file to a "tree" object with the program</p><div class="literallayout"><p>$Â git-write-tree</p></div><p>that doesn't come with any options - it will just write out the
+an object still matches its old backing store object.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="index-to-object-database"></a>index -> object database</h3></div></div></div><p>You write your current index file to a "tree" object with the program</p><div class="literallayout"><p>$Â git-write-tree</p></div><p>that doesn't come with any options - it will just write out the
current index into the set of tree objects that describe that state,
and it will return the name of the resulting top-level tree. You can
use that tree to re-generate the index at any time by going in the
-other direction:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278136"></a>object database -> index</h3></div></div></div><p>You read a "tree" file from the object database, and use that to
+other direction:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="object-database-to-index"></a>object database -> index</h3></div></div></div><p>You read a "tree" file from the object database, and use that to
populate (and overwrite - don't do this if your index contains any
unsaved state that you might want to restore later!) your current
index. Normal operation is just</p><div class="literallayout"><p>$ git-read-tree <sha1 of tree></p></div><p>and your index file will now be equivalent to the tree that you saved
earlier. However, that is only your <span class="emphasis"><em>index</em></span> file: your working
-directory contents have not been modified.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278167"></a>index -> working directory</h3></div></div></div><p>You update your working directory from the index by "checking out"
+directory contents have not been modified.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="index-to-working-directory"></a>index -> working directory</h3></div></div></div><p>You update your working directory from the index by "checking out"
files. This is not a very common operation, since normally you'd just
keep your files updated, and rather than write to your working
directory, you'd tell the index files about the changes in your
if you have an old version of the tree already checked out, you will
need to use the "-f" flag (<span class="emphasis"><em>before</em></span> the "-a" flag or the filename) to
<span class="emphasis"><em>force</em></span> the checkout.</p><p>Finally, there are a few odds and ends which are not purely moving
-from one representation to the other:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278230"></a>Tying it all together</h3></div></div></div><p>To commit a tree you have instantiated with "git-write-tree", you'd
+from one representation to the other:</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="tying-it-all-together"></a>Tying it all together</h3></div></div></div><p>To commit a tree you have instantiated with "git-write-tree", you'd
create a "commit" object that refers to that tree and the history
behind it - most notably the "parent" commits that preceded it in
history.</p><p>Normally a "commit" has one parent: the previous state of the tree
                    |  Working  |<br>
                    | Directory |<br>
                    +-----------+<br>
-</p></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id278325"></a>Examining the data</h2></div></div></div><p>You can examine the data represented in the object database and the
+</p></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="examining-the-data"></a>Examining the data</h2></div></div></div><p>You can examine the data represented in the object database and the
index with various helper tools. For every object, you can use
<a href="git-cat-file.html" target="_top">git-cat-file(1)</a> to examine details about the
object:</p><div class="literallayout"><p>$ git-cat-file -t <objectname></p></div><p>shows the type of the object, and once you have the type (which is
readable form.</p><p>It's especially instructive to look at "commit" objects, since those
tend to be small and fairly self-explanatory. In particular, if you
follow the convention of having the top commit name in <code class="literal">.git/HEAD</code>,
-you can do</p><div class="literallayout"><p>$ git-cat-file commit HEAD</p></div><p>to see what the top commit was.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id278403"></a>Merging multiple trees</h2></div></div></div><p>Git helps you do a three-way merge, which you can expand to n-way by
+you can do</p><div class="literallayout"><p>$ git-cat-file commit HEAD</p></div><p>to see what the top commit was.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="merging-multiple-trees"></a>Merging multiple trees</h2></div></div></div><p>Git helps you do a three-way merge, which you can expand to n-way by
repeating the merge procedure arbitrary times until you finally
"commit" the state. The normal situation is that you'd only do one
three-way merge (two parents), and commit it, but if you like to, you
now look up the "tree" objects of those commits, which you can easily
do with (for example)</p><div class="literallayout"><p>$ git-cat-file commit <commitname> | head -1</p></div><p>since the tree object information is always the first line in a commit
object.</p><p>Once you know the three trees you are going to merge (the one "original"
-tree, aka the common case, and the two "result" trees, aka the branches
+tree, aka the common tree, and the two "result" trees, aka the branches
you want to merge), you do a "merge" read into the index. This will
complain if it has to throw away your old index contents, so you should
make sure that you've committed those - in fact you would normally
always do a merge against your last commit (which should thus match what
you have in your current index anyway).</p><p>To do the merge, do</p><div class="literallayout"><p>$ git-read-tree -m -u <origtree> <yourtree> <targettree></p></div><p>which will do all trivial merge operations for you directly in the
index file, and you can just write the result out with
-<code class="literal">git-write-tree</code>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id278490"></a>Merging multiple trees, continued</h2></div></div></div><p>Sadly, many merges aren't trivial. If there are files that have
+<code class="literal">git-write-tree</code>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="merging-multiple-trees-2"></a>Merging multiple trees, continued</h2></div></div></div><p>Sadly, many merges aren't trivial. If there are files that have
been added.moved or removed, or if both branches have modified the
same file, you will be left with an index tree that contains "merge
entries" in it. Such an index tree can <span class="emphasis"><em>NOT</em></span> be written out to a tree
above example shows is that file <code class="literal">hello.c</code> was changed from
<code class="literal">$orig</code> to <code class="literal">HEAD</code> and <code class="literal">$orig</code> to <code class="literal">$target</code> in a different way.
You could resolve this by running your favorite 3-way merge
-program, e.g. <code class="literal">diff3</code> or <code class="literal">merge</code>, on the blob objects from
-these three stages yourself, like this:</p><div class="literallayout"><p>$ git-cat-file blob 263414f... >hello.c~1<br>
+program, e.g. <code class="literal">diff3</code>, <code class="literal">merge</code>, or git's own merge-file, on
+the blob objects from these three stages yourself, like this:</p><div class="literallayout"><p>$ git-cat-file blob 263414f... >hello.c~1<br>
$ git-cat-file blob 06fa6a2... >hello.c~2<br>
$ git-cat-file blob cc44c73... >hello.c~3<br>
-$ merge hello.c~2 hello.c~1 hello.c~3</p></div><p>This would leave the merge result in <code class="literal">hello.c~2</code> file, along
+$ git merge-file hello.c~2 hello.c~1 hello.c~3</p></div><p>This would leave the merge result in <code class="literal">hello.c~2</code> file, along
with conflict markers if there are conflicts. After verifying
the merge result makes sense, you can tell git what the final
merge result for this file is by:</p><div class="literallayout"><p>$ mv -f hello.c~2 hello.c<br>
to help you understand what conceptually happens under the hood.
In practice, nobody, not even git itself, uses three <code class="literal">git-cat-file</code>
for this. There is <code class="literal">git-merge-index</code> program that extracts the
-stages to temporary files and calls a "merge" script on it:</p><div class="literallayout"><p>$ git-merge-index git-merge-one-file hello.c</p></div><p>and that is what higher level <code class="literal">git merge -s resolve</code> is implemented with.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id278750"></a>How git stores objects efficiently: pack files</h2></div></div></div><p>We've seen how git stores each object in a file named after the
+stages to temporary files and calls a "merge" script on it:</p><div class="literallayout"><p>$ git-merge-index git-merge-one-file hello.c</p></div><p>and that is what higher level <code class="literal">git merge -s resolve</code> is implemented with.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="pack-files"></a>How git stores objects efficiently: pack files</h2></div></div></div><p>We've seen how git stores each object in a file named after the
object's SHA1 hash.</p><p>Unfortunately this system becomes inefficient once a project has a
lot of objects. Try this on an old project:</p><div class="literallayout"><p>$ git count-objects<br>
6930 objects, 47620 kilobytes</p></div><p>The first number is the number of objects which are kept in
objects. They are not a problem.</p><p>The most common cause of dangling objects is that you've rebased a
branch, or you have pulled from somebody else who rebased a branch—see
<a href="#cleaning-up-history" title="Chapter 6. Rewriting history and maintaining patch series">Chapter 6, <i>Rewriting history and maintaining patch series</i></a>. In that case, the old head of the original
-branch still exists, as does obviously everything it pointed to. The
-branch pointer itself just doesn't, since you replaced it with another
-one.</p><p>There are also other situations too that cause dangling objects. For
+branch still exists, as does everything it pointed to. The branch
+pointer itself just doesn't, since you replaced it with another one.</p><p>There are also other situations that cause dangling objects. For
example, a "dangling blob" may arise because you did a "git add" of a
file, but then, before you actually committed it and made it part of the
bigger picture, you changed something else in that file and committed
even be very useful: if you screw something up, the dangling objects can
be how you recover your old tree (say, you did a rebase, and realized
that you really didn't want to - you can look at what dangling objects
-you have, and decide to reset your head to some old dangling state).</p><p>For commits, the most useful thing to do with dangling objects tends to
-be to do a simple</p><div class="literallayout"><p>$ gitk <dangling-commit-sha-goes-here> --not --all</p></div><p>For blobs and trees, you can't do the same, but you can examine them.
-You can just do</p><div class="literallayout"><p>$ git show <dangling-blob/tree-sha-goes-here></p></div><p>to show what the contents of the blob were (or, for a tree, basically
+you have, and decide to reset your head to some old dangling state).</p><p>For commits, you can just use:</p><div class="literallayout"><p>$ gitk <dangling-commit-sha-goes-here> --not --all</p></div><p>This asks for all the history reachable from the given commit but not
+from any branch, tag, or other reference. If you decide it's something
+you want, you can always create a new reference to it, e.g.,</p><div class="literallayout"><p>$ git branch recovered-branch <dangling-commit-sha-goes-here></p></div><p>For blobs and trees, you can't do the same, but you can still examine
+them. You can just do</p><div class="literallayout"><p>$ git show <dangling-blob/tree-sha-goes-here></p></div><p>to show what the contents of the blob were (or, for a tree, basically
what the "ls" for that directory was), and that may give you some idea
of what the operation was that left that dangling object.</p><p>Usually, dangling blobs and trees aren't very interesting. They're
almost always the result of either being a half-way mergebase (the blob
Running it while somebody is actually changing the repository can cause
confusing and scary messages, but it won't actually do anything bad. In
contrast, running "git prune" while somebody is actively changing the
-repository is a <span class="strong"><strong>BAD</strong></span> idea).</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id279010"></a>Chapter 9. GIT Glossary</h2></div></div></div><div class="variablelist"><dl><dt><span class="term">
+repository is a <span class="strong"><strong>BAD</strong></span> idea).</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="glossary"></a>Chapter 9. GIT Glossary</h2></div></div></div><div class="variablelist"><dl><dt><span class="term">
<a name="def_alternate_object_database"></a>alternate object database
</span></dt><dd>
Via the alternates mechanism, a <a href="#def_repository">repository</a> can
</span></dt><dd>
The set of files and directories currently being worked on, i.e. you can
work in your <a href="#def_working_tree">working tree</a> without using git at all.
-</dd></dl></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id282289"></a>Chapter 10. Notes and todo list for this manual</h2></div></div></div><p>This is a work in progress.</p><p>The basic requirements:
+</dd></dl></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="todo"></a>Chapter 10. Notes and todo list for this manual</h2></div></div></div><p>This is a work in progress.</p><p>The basic requirements:
- It must be readable in order, from beginning to end, by
someone intelligent with a basic grasp of the unix
commandline, but without any special knowledge of git. If
$ man git-clone
------------------------------------------------
+[[git-quick-start]]
Git Quick Start
===============
This is a quick summary of the major commands; the following chapters
will explain how these work in more detail.
+[[quick-creating-a-new-repository]]
Creating a new repository
-------------------------
$ cd project
-----------------------------------------------
+[[managing-branches]]
Managing branches
-----------------
-----------------------------------------------
-$ git branch # list all branches in this repo
+$ git branch # list all local branches in this repo
$ git checkout test # switch working directory to branch "test"
$ git branch new # create branch "new" starting at current HEAD
$ git branch -d new # delete branch "new"
-----------------------------------------------
+[[exploring-history]]
Exploring history
-----------------
# repeat until done.
-----------------------------------------------
+[[making-changes]]
Making changes
--------------
Make sure git knows who to blame:
------------------------------------------------
-$ cat >~/.gitconfig <<\EOF
+$ cat >>~/.gitconfig <<\EOF
[user]
name = Your Name Comes Here
email = you@yourdomain.example.com
$ git commit -a # use latest content of all tracked files
-----------------------------------------------
+[[merging]]
Merging
-------
$ git pull . test # equivalent to git merge test
-----------------------------------------------
+[[sharing-your-changes]]
Sharing your changes
--------------------
$ git push example test
-----------------------------------------------
+[[repository-maintenance]]
Repository maintenance
----------------------
$ git gc
-----------------------------------------------
+[[repositories-and-branches]]
Repositories and Branches
=========================
+[[how-to-get-a-git-repository]]
How to get a git repository
---------------------------
In most of the following, examples will be taken from one of the two
repositories above.
+[[how-to-check-out]]
How to check out a different version of a project
-------------------------------------------------
with no way to find the history it used to point to; so use this command
carefully.
+[[understanding-commits]]
Understanding History: Commits
------------------------------
history, including file data and directory contents, is stored in an object
with a name that is a hash of its contents.
+[[understanding-reachability]]
Understanding history: commits, parents, and reachability
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
that Y is a descendent of X, or that there is a chain of parents
leading from commit Y to commit X.
+[[history-diagrams]]
Understanding history: History diagrams
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we need to talk about a particular commit, the character "o" may
be replaced with another letter or number.
+[[what-is-a-branch]]
Understanding history: What is a branch?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
However, when no confusion will result, we often just use the term
"branch" both for branches and for branch heads.
+[[manipulating-branches]]
Manipulating branches
---------------------
including using a branch name or a tag name
git branch -d <branch>::
delete the branch <branch>; if the branch you are deleting
- points to a commit which is not reachable from this branch,
- this command will fail with a warning.
+ points to a commit which is not reachable from the current
+ branch, this command will fail with a warning.
git branch -D <branch>::
even if the branch points to a commit not reachable
from the current branch, you may know that that commit
------------------------------------------------
$ cat .git/HEAD
427abfa28afedffadfca9dd8b067eb6d36bac53f
-git branch
+$ git branch
* (no branch)
master
------------------------------------------------
In this case we say that the HEAD is "detached".
-This can be an easy way to check out a particular version without having
-to make up a name for a new branch. However, keep in mind that when you
-switch away from the (for example, by checking out something else), you
-can lose track of what the HEAD used to point to.
+This is an easy way to check out a particular version without having to
+make up a name for the new branch. You can still create a new branch
+(or tag) for this version later if you decide to.
+[[examining-remote-branches]]
Examining branches from a remote repository
-------------------------------------------
The full name is occasionally useful if, for example, there ever
exists a tag and a branch with the same name.
-As another useful shortcut, if the repository "origin" posesses only
-a single branch, you can refer to that branch as just "origin".
-
-More generally, if you have defined a remote repository named
-"example", you can refer to the branch in that repository as
-"example". And for a repository with multiple branches, this will
-refer to the branch designated as the "HEAD" branch.
+As another useful shortcut, the "HEAD" of a repository can be referred
+to just using the name of that repository. So, for example, "origin"
+is usually a shortcut for the HEAD branch in the repository "origin".
For the complete list of paths which git checks for references, and
the order it uses to decide which to choose when there are multiple
repository. It will not touch any of your own branches--not even the
"master" branch that was created for you on clone.
+[[fetching-branches]]
Fetching branches from other repositories
-----------------------------------------
text editor. (See the "CONFIGURATION FILE" section of
gitlink:git-config[1] for details.)
+[[exploring-git-history]]
Exploring git history
=====================
We start with one specialized tool that is useful for finding the
commit that introduced a bug into a project.
+[[using-bisect]]
How to use bisect to find a regression
--------------------------------------
then test, run "bisect good" or "bisect bad" as appropriate, and
continue.
+[[naming-commits]]
Naming commits
--------------
e05db0fd4f31dde7005f075a84f96b360d05984b
-------------------------------------------------
+[[creating-tags]]
Creating tags
-------------
You can use stable-1 to refer to the commit 1b2e1d63ff.
-This creates a "lightweight" tag. If the tag is a tag you wish to
-share with others, and possibly sign cryptographically, then you
-should create a tag object instead; see the gitlink:git-tag[1] man
-page for details.
+This creates a "lightweight" tag. If you would also like to include a
+comment with the tag, and possibly sign it cryptographically, then you
+should create a tag object instead; see the gitlink:git-tag[1] man page
+for details.
+[[browsing-revisions]]
Browsing revisions
------------------
multiple independent lines of development, the particular order that
commits are listed in may be somewhat arbitrary.
+[[generating-diffs]]
Generating diffs
----------------
not reachable from test, then the combined result of these patches
will not be the same as the diff produced by the git-diff example.
+[[viewing-old-file-versions]]
Viewing old file versions
-------------------------
Before the colon may be anything that names a commit, and after it
may be any path to a file tracked by git.
+[[history-examples]]
Examples
--------
+[[checking-for-equal-branches]]
Check whether two branches point at the same history
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
will return no commits when the two branches are equal.
+[[finding-tagged-descendants]]
Find first tagged version including a given fix
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from v1.5.0-rc2, but not from v1.5.0-rc0.
+[[Developing-with-git]]
Developing with git
===================
+[[telling-git-your-name]]
Telling git your name
---------------------
Before creating any commits, you should introduce yourself to git. The
-easiest way to do so is:
+easiest way to do so is to make sure the following lines appear in a
+file named .gitconfig in your home directory:
------------------------------------------------
-$ cat >~/.gitconfig <<\EOF
[user]
name = Your Name Comes Here
email = you@yourdomain.example.com
-EOF
------------------------------------------------
(See the "CONFIGURATION FILE" section of gitlink:git-config[1] for
details on the configuration file.)
+[[creating-a-new-repository]]
Creating a new repository
-------------------------
$ git diff # difference between the index file and your
# working directory; changes that would not
# be included if you ran "commit" now.
+$ git diff HEAD # difference between HEAD and working tree; what
+ # would be committed if you ran "commit -a" now.
$ git status # a brief per-file summary of the above.
-------------------------------------------------
+[[creating-good-commit-messages]]
Creating good commit messages
-----------------------------
the first line on the Subject line and the rest of the commit in the
body.
+[[how-to-merge]]
How to merge
------------
has two parents, one pointing to the top of the current branch, and
one to the top of the other branch.
-In more detail:
-
[[resolving-a-merge]]
Resolving a merge
-----------------
The above is all you need to know to resolve a simple merge. But git
also provides more information to help resolve conflicts:
+[[conflict-resolution]]
Getting conflict-resolution help during a merge
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These will display all commits which exist only on HEAD or on
MERGE_HEAD, and which touch an unmerged file.
+You may also use gitlink:git-mergetool, which lets you merge the
+unmerged files using external tools such as emacs or kdiff3.
+
Each time you resolve the conflicts in a file and update the index:
-------------------------------------------------
itself have been merged into another branch, as doing so may confuse
further merges.
+[[fast-forwards]]
Fast-forward merges
-------------------
parents, one pointing at each of the two lines of development that
were merged.
-However, if one of the two lines of development is completely
-contained within the other--so every commit present in the one is
-already contained in the other--then git just performs a
-<<fast-forwards,fast forward>>; the head of the current branch is
-moved forward to point at the head of the merged-in branch, without
-any new commits being created.
+However, if the current branch is a descendant of the other--so every
+commit present in the one is already contained in the other--then git
+just performs a "fast forward"; the head of the current branch is moved
+forward to point at the head of the merged-in branch, without any new
+commits being created.
+[[fixing-mistakes]]
Fixing mistakes
---------------
change, and cannot correctly perform repeated merges from
a branch that has had its history changed.
+[[reverting-a-commit]]
Fixing a mistake with a new commit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this is an advanced topic to be left for
<<cleaning-up-history,another chapter>>.
+[[checkout-of-path]]
Checking out an old version of a file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which will display the given version of the file.
+[[ensuring-good-performance]]
Ensuring good performance
-------------------------
to recompress the archive. This can be very time-consuming, so
you may prefer to run git-gc when you are not doing other work.
+
+[[ensuring-reliability]]
Ensuring reliability
--------------------
+[[checking-for-corruption]]
Checking the repository for corruption
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
-------------------------------------------------
-Dangling objects are objects that are harmless, but also unnecessary;
-you can remove them at any time with gitlink:git-prune[1] or the --prune
+Dangling objects are not a problem. At worst they may take up a little
+extra disk space. They can sometimes provide a last-resort method of
+recovery lost work--see <<dangling-objects>> for details. However, if
+you want, you may remove them with gitlink:git-prune[1] or the --prune
option to gitlink:git-gc[1]:
-------------------------------------------------
git-gc when run without any options), it is not safe to prune while
other git operations are in progress in the same repository.
-For more about dangling objects, see <<dangling-objects>>.
-
-
+[[recovering-lost-changes]]
Recovering lost changes
~~~~~~~~~~~~~~~~~~~~~~~
+[[reflogs]]
Reflogs
^^^^^^^
$ git show master@{3} # 3, ... changes ago.
$ gitk master@{yesterday} # See where it pointed yesterday,
$ gitk master@{"1 week ago"} # ... or last week
+$ git log --walk-reflogs master # show reflog entries for master
-------------------------------------------------
+A separate reflog is kept for the HEAD, so
+
+-------------------------------------------------
+$ git show HEAD@{"1 week ago"}
+-------------------------------------------------
+
+will show what HEAD pointed to one week ago, not what the current branch
+pointed to one week ago. This allows you to see the history of what
+you've checked out.
+
The reflogs are kept by default for 30 days, after which they may be
pruned. See gitlink:git-reflog[1] and gitlink:git-gc[1] to learn
how to control this pruning, and see the "SPECIFYING REVISIONS"
same project, the reflog history is not shared: it tells you only about
how the branches in your local repository have changed over time.
+[[dangling-object-recovery]]
Examining dangling objects
^^^^^^^^^^^^^^^^^^^^^^^^^^
-In some situations the reflog may not be able to save you. For
-example, suppose you delete a branch, then realize you need the history
-it contained. The reflog is also deleted; however, if you have not
-yet pruned the repository, then you may still be able to find
-the lost commits; run git-fsck and watch for output that mentions
-"dangling commits":
+In some situations the reflog may not be able to save you. For example,
+suppose you delete a branch, then realize you need the history it
+contained. The reflog is also deleted; however, if you have not yet
+pruned the repository, then you may still be able to find the lost
+commits in the dangling objects that git-fsck reports. See
+<<dangling-objects>> for the details.
-------------------------------------------------
$ git fsck
$ git branch recovered-branch 7281251ddd
------------------------------------------------
+Other types of dangling objects (blobs and trees) are also possible, and
+dangling objects can arise in other situations.
+
+[[sharing-development]]
Sharing development with others
===============================
$ git pull
-------------------------------------------------
-See the descriptions of the branch.<name>.remote and
-branch.<name>.merge options in gitlink:git-config[1] to learn
-how to control these defaults depending on the current branch.
+See the descriptions of the branch.<name>.remote and branch.<name>.merge
+options in gitlink:git-config[1] to learn how to control these defaults
+depending on the current branch. Also note that the --track option to
+gitlink:git-branch[1] and gitlink:git-checkout[1] can be used to
+automatically set the default remote branch to pull from at the time
+that a branch is created:
+
+-------------------------------------------------
+$ git checkout --track -b origin/maint maint
+-------------------------------------------------
In addition to saving you keystrokes, "git pull" also helps you by
producing a default commit message documenting the branch and
are roughly equivalent. The former is actually very commonly used.
+[[submitting-patches]]
Submitting patches to a project
-------------------------------
Consult the mailing list for your project first to determine how they
prefer such patches be handled.
+[[importing-patches]]
Importing patches to a project
------------------------------
first create a new clone of the repository:
-------------------------------------------------
-$ git clone --bare proj-clone.git
+$ git clone --bare proj.git
-------------------------------------------------
-The resulting directory proj-clone.git will contains a "bare" git
+The resulting directory proj.git will contains a "bare" git
repository--it is just the contents of the ".git" directory, without
a checked-out copy of a working directory.
-Next, copy proj-clone.git to the server where you plan to host the
+Next, copy proj.git to the server where you plan to host the
public repository. You can use scp, rsync, or whatever is most
convenient.
-------------------------------------------------
$ mv proj.git /home/you/public_html/proj.git
$ cd proj.git
-$ git update-server-info
+$ git --bare update-server-info
$ chmod a+x hooks/post-update
-------------------------------------------------
save typing; so, for example, after
-------------------------------------------------
-$ cat >.git/config <<EOF
+$ cat >>.git/config <<EOF
[remote "public-repo"]
url = ssh://yourserver.com/~you/proj.git
EOF
and remote.<name>.push options in gitlink:git-config[1] for
details.
+[[setting-up-a-shared-repository]]
Setting up a shared repository
------------------------------
link:cvs-migration.txt[git for CVS users] for instructions on how to
set this up.
+[[setting-up-gitweb]]
Allow web browsing of a repository
----------------------------------
project's files and history without having to install git; see the file
gitweb/INSTALL in the git source tree for instructions on setting it up.
+[[sharing-development-examples]]
Examples
--------
However, there is a situation in which it can be useful to violate this
assumption.
+[[patch-series]]
Creating the perfect patch series
---------------------------------
use them, and then explain some of the problems that can arise because
you are rewriting history.
+[[using-git-rebase]]
Keeping a patch series up to date using git-rebase
--------------------------------------------------
$ git rebase --abort
-------------------------------------------------
+[[modifying-one-commit]]
Modifying a single commit
-------------------------
"modified" existing commits; instead, you have replaced the old commits with
new commits having new object names.
+[[reordering-patch-series]]
Reordering or selecting from a patch series
-------------------------------------------
Then modify, reorder, or eliminate patches as preferred before applying
them again with gitlink:git-am[1].
+[[patch-series-tools]]
Other tools
-----------
purpose of maintaining a patch series. These are outside of the scope of
this manual.
+[[problems-with-rewriting-history]]
Problems with rewriting history
-------------------------------
For true distributed development that supports proper merging,
published branches should never be rewritten.
+[[advanced-branch-management]]
Advanced branch management
==========================
+[[fetching-individual-branches]]
Fetching individual branches
----------------------------
will create a new branch named "example-master" and store in it the
branch named "master" from the repository at the given URL. If you
already have a branch named example-master, it will attempt to
-"fast-forward" to the commit given by example.com's master branch. So
-next we explain what a fast-forward is:
+<<fast-forwards,fast-forward>> to the commit given by example.com's
+master branch. In more detail:
-[[fast-forwards]]
-Understanding git history: fast-forwards
-----------------------------------------
+[[fetch-fast-forwards]]
+git fetch and fast-forwards
+---------------------------
In the previous example, when updating an existing branch, "git
fetch" checks to make sure that the most recent commit on the remote
branch is a descendant of the most recent commit on your copy of the
branch before updating your copy of the branch to point at the new
-commit. Git calls this process a "fast forward".
+commit. Git calls this process a <<fast-forwards,fast forward>>.
A fast forward looks something like this:
unless you've already created a reference of your own pointing to
them.
+[[forcing-fetch]]
Forcing git fetch to do non-fast-forward updates
------------------------------------------------
$ git fetch git://example.com/proj.git +master:refs/remotes/example/master
-------------------------------------------------
-Note the addition of the "+" sign. Be aware that commits that the
-old version of example/master pointed at may be lost, as we saw in
-the previous section.
+Note the addition of the "+" sign. Alternatively, you can use the "-f"
+flag to force updates of all the fetched branches, as in:
+
+-------------------------------------------------
+$ git fetch -f origin
+-------------------------------------------------
+
+Be aware that commits that the old version of example/master pointed at
+may be lost, as we saw in the previous section.
+[[remote-branch-configuration]]
Configuring remote branches
---------------------------
Git depends on two fundamental abstractions: the "object database", and
the "current directory cache" aka "index".
+[[the-object-database]]
The Object Database
-------------------
to other objects (by referencing their SHA1 hash), and so you can
build up a hierarchy of objects.
-All objects have a statically determined "type" aka "tag", which is
+All objects have a statically determined "type" which is
determined at object creation time, and which identifies the format of
the object (i.e. how it is used, and how it can refer to other
objects). There are currently four different object types: "blob",
that directory hierarchy.
As a special case, a commit object with no parents is called the "root"
-object, and is the point of an initial project commit. Each project
+commit, and is the point of an initial project commit. Each project
must have at least one root, and while you can tie several different
root objects together into one project by creating a commit object which
has two or more separate roots as its ultimate parents, that's probably
The object types in some more detail:
+[[blob-object]]
Blob Object
-----------
A blob is typically created when gitlink:git-update-index[1]
is run, and its data can be accessed by gitlink:git-cat-file[1].
+[[tree-object]]
Tree Object
-----------
its data can be accessed by gitlink:git-ls-tree[1].
Two trees can be compared with gitlink:git-diff-tree[1].
+[[commit-object]]
Commit Object
-------------
The parents do not have to actually have any relationship with the
result, for example.
-Note on commits: unlike real SCM's, commits do not contain
+Note on commits: unlike some SCM's, commits do not contain
rename information or file mode change information. All of that is
implicit in the trees involved (the result tree, and the result trees
of the parents), and describing that makes no sense in this idiotic
A commit is created with gitlink:git-commit-tree[1] and
its data can be accessed by gitlink:git-cat-file[1].
+[[trust]]
Trust
-----
To assist in this, git also provides the tag object...
+[[tag-object]]
Tag Object
----------
gitlink:git-verify-tag[1].
+[[the-index]]
The "index" aka "Current Directory Cache"
-----------------------------------------
The index is a simple binary file, which contains an efficient
-representation of a virtual directory content at some random time. It
+representation of the contents of a virtual directory. It
does so by a simple array that associates a set of names, dates,
permissions and content (aka "blob") objects together. The cache is
always kept ordered by name, and names are unique (with a few very
+[[the-workflow]]
The Workflow
------------
from the database or from the working directory. Thus there are four
main combinations:
+[[working-directory-to-index]]
working directory -> index
~~~~~~~~~~~~~~~~~~~~~~~~~~
it will only update the fields that are used to quickly test whether
an object still matches its old backing store object.
+[[index-to-object-database]]
index -> object database
~~~~~~~~~~~~~~~~~~~~~~~~
use that tree to re-generate the index at any time by going in the
other direction:
+[[object-database-to-index]]
object database -> index
~~~~~~~~~~~~~~~~~~~~~~~~
earlier. However, that is only your 'index' file: your working
directory contents have not been modified.
+[[index-to-working-directory]]
index -> working directory
~~~~~~~~~~~~~~~~~~~~~~~~~~
Finally, there are a few odds and ends which are not purely moving
from one representation to the other:
+[[tying-it-all-together]]
Tying it all together
~~~~~~~~~~~~~~~~~~~~~
------------
+[[examining-the-data]]
Examining the data
------------------
to see what the top commit was.
+[[merging-multiple-trees]]
Merging multiple trees
----------------------
object.
Once you know the three trees you are going to merge (the one "original"
-tree, aka the common case, and the two "result" trees, aka the branches
+tree, aka the common tree, and the two "result" trees, aka the branches
you want to merge), you do a "merge" read into the index. This will
complain if it has to throw away your old index contents, so you should
make sure that you've committed those - in fact you would normally
`git-write-tree`.
+[[merging-multiple-trees-2]]
Merging multiple trees, continued
---------------------------------
above example shows is that file `hello.c` was changed from
`$orig` to `HEAD` and `$orig` to `$target` in a different way.
You could resolve this by running your favorite 3-way merge
-program, e.g. `diff3` or `merge`, on the blob objects from
-these three stages yourself, like this:
+program, e.g. `diff3`, `merge`, or git's own merge-file, on
+the blob objects from these three stages yourself, like this:
------------------------------------------------
$ git-cat-file blob 263414f... >hello.c~1
$ git-cat-file blob 06fa6a2... >hello.c~2
$ git-cat-file blob cc44c73... >hello.c~3
-$ merge hello.c~2 hello.c~1 hello.c~3
+$ git merge-file hello.c~2 hello.c~1 hello.c~3
------------------------------------------------
This would leave the merge result in `hello.c~2` file, along
and that is what higher level `git merge -s resolve` is implemented with.
+[[pack-files]]
How git stores objects efficiently: pack files
----------------------------------------------
The most common cause of dangling objects is that you've rebased a
branch, or you have pulled from somebody else who rebased a branch--see
<<cleaning-up-history>>. In that case, the old head of the original
-branch still exists, as does obviously everything it pointed to. The
-branch pointer itself just doesn't, since you replaced it with another
-one.
+branch still exists, as does everything it pointed to. The branch
+pointer itself just doesn't, since you replaced it with another one.
-There are also other situations too that cause dangling objects. For
+There are also other situations that cause dangling objects. For
example, a "dangling blob" may arise because you did a "git add" of a
file, but then, before you actually committed it and made it part of the
bigger picture, you changed something else in that file and committed
that you really didn't want to - you can look at what dangling objects
you have, and decide to reset your head to some old dangling state).
-For commits, the most useful thing to do with dangling objects tends to
-be to do a simple
+For commits, you can just use:
------------------------------------------------
$ gitk <dangling-commit-sha-goes-here> --not --all
------------------------------------------------
-For blobs and trees, you can't do the same, but you can examine them.
-You can just do
+This asks for all the history reachable from the given commit but not
+from any branch, tag, or other reference. If you decide it's something
+you want, you can always create a new reference to it, e.g.,
+
+------------------------------------------------
+$ git branch recovered-branch <dangling-commit-sha-goes-here>
+------------------------------------------------
+
+For blobs and trees, you can't do the same, but you can still examine
+them. You can just do
------------------------------------------------
$ git show <dangling-blob/tree-sha-goes-here>
contrast, running "git prune" while somebody is actively changing the
repository is a *BAD* idea).
+[[glossary]]
include::glossary.txt[]
+[[todo]]
Notes and todo list for this manual
===================================