-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Git User's Manual</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</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="#id232445">Exploring history</a></span></dt><dt><span class="section"><a href="#id232489">Making changes</a></span></dt><dt><span class="section"><a href="#id233361">Merging</a></span></dt><dt><span class="section"><a href="#id233378">Sharing your changes</a></span></dt><dt><span class="section"><a href="#id233463">Repository maintenance</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id232662">2. Repositories and Branches</a></span></dt><dd><dl><dt><span class="section"><a href="#id232667">How to get a git repository</a></span></dt><dt><span class="section"><a href="#id232724">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#id273520">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="#id273650">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="#id274208">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="#id274655">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="#id274713">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="#id275502">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="#id275716">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="#id275812">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="#id276043">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="#id276175">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#id276224">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="#id276637">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#id276656">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#id276669">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="#id276700">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#id276775">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#id276905">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#id277002">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#id277062">Other tools</a></span></dt><dt><span class="section"><a href="#id277075">Problems with rewriting history</a></span></dt></dl></dd><dt><span class="chapter"><a href="#id277146">7. Advanced branch management</a></span></dt><dd><dl><dt><span class="section"><a href="#id277152">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="#id277273">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#id277300">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="#id277438">The Object Database</a></span></dt><dt><span class="section"><a href="#id277591">Blob Object</a></span></dt><dt><span class="section"><a href="#id232225">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="#id277877">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="#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
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="#id232445">Exploring history</a></span></dt><dt><span class="section"><a href="#id232489">Making changes</a></span></dt><dt><span class="section"><a href="#id233361">Merging</a></span></dt><dt><span class="section"><a href="#id233378">Sharing your changes</a></span></dt><dt><span class="section"><a href="#id233463">Repository maintenance</a></span></dt></dl></div><p>This is a quick summary of the major commands; the following chapters
+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>
$ cd project<br>
$ git init<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="id232445"></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="id232446"></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>
$ 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="id233361"></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="id233362"></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>
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="id233463"></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="id232662"></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="#id232667">How to get a git repository</a></span></dt><dt><span class="section"><a href="#id232724">How to check out a different version of a project</a></span></dt><dt><span class="section"><a href="#id273520">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="#id273650">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="id232667"></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="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
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="id232724"></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="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
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="id273520"></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="id273521"></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>
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="id273650"></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="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
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
...</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="#id274208">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="#id274655">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="#id274713">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="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
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="id274208"></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="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
"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
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="id274655"></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="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
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="id274713"></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="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.
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="#id275502">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="#id275716">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="#id275812">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
+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>
name = Your Name Comes Here<br>
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="id275502"></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="id275503"></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
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="id275716"></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="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
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
<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
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="id275812"></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="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
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>
(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="id276043"></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="#id276175">Submitting patches to a project</a></span></dt><dt><span class="section"><a href="#id276224">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="#id276637">Setting up a shared repository</a></span></dt><dt><span class="section"><a href="#id276656">Allow web browsing of a repository</a></span></dt><dt><span class="section"><a href="#id276669">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></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
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
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="id276175"></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="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
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="id276224"></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="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
"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
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="id276637"></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="id276705"></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="id276656"></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="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
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="id276669"></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="#id276700">Creating the perfect patch series</a></span></dt><dt><span class="section"><a href="#id276775">Keeping a patch series up to date using git-rebase</a></span></dt><dt><span class="section"><a href="#id276905">Modifying a single commit</a></span></dt><dt><span class="section"><a href="#id277002">Reordering or selecting from a patch series</a></span></dt><dt><span class="section"><a href="#id277062">Other tools</a></span></dt><dt><span class="section"><a href="#id277075">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="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
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="id276700"></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="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
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="id276775"></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="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
"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="id276905"></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="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
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="id277002"></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="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
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="id277062"></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="id277131"></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="id277075"></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="id277144"></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="id277146"></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="#id277152">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="#id277273">Forcing git fetch to do non-fast-forward updates</a></span></dt><dt><span class="section"><a href="#id277300">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="id277152"></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="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
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
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="id277273"></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
+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="id277300"></a>Configuring remote branches</h2></div></div></div><p>We saw above that "origin" is just a shortcut to refer to the
+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
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="#id277438">The Object Database</a></span></dt><dt><span class="section"><a href="#id277591">Blob Object</a></span></dt><dt><span class="section"><a href="#id232225">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="#id277877">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="id277438"></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="#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
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
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="id277591"></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="id277659"></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="id232225"></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="id277703"></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
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="id277877"></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="id277878"></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