From 3d30fd50da4218bf2dddc680132f2688108d94e4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 8 May 2007 00:32:53 +0000 Subject: [PATCH] Autogenerated HTML docs for v1.5.2-rc2-21-g3082 --- git-add.html | 13 +- git-add.txt | 6 +- git-clean.html | 4 +- git-clean.txt | 2 +- git-cvsexportcommit.html | 4 +- git-cvsexportcommit.txt | 2 +- git-ls-files.html | 6 +- git-ls-files.txt | 4 +- git-update-index.html | 7 +- git-update-index.txt | 6 +- git.html | 9 +- git.txt | 7 +- user-manual.html | 277 ++++++++++++++++++++------------------- user-manual.txt | 258 +++++++++++++++++++++++++----------- 14 files changed, 369 insertions(+), 236 deletions(-) diff --git a/git-add.html b/git-add.html index e6cbd3278..48114b6bb 100644 --- a/git-add.html +++ b/git-add.html @@ -272,7 +272,7 @@ git-add(1) Manual Page

SYNOPSIS

-

git-add [-n] [-v] [-f] [--interactive | -i] [--] <file>…

+

git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] <file>…

DESCRIPTION

@@ -343,6 +343,15 @@ commit.

+-u +
+
+

+ Update all files that git already knows about. This is what + "git commit -a" does in preparation for making a commit. +

+
+
--
@@ -536,7 +545,7 @@ diff
diff --git a/git-add.txt b/git-add.txt index 755d7186f..ea2701846 100644 --- a/git-add.txt +++ b/git-add.txt @@ -7,7 +7,7 @@ git-add - Add file contents to the changeset to be committed next SYNOPSIS -------- -'git-add' [-n] [-v] [-f] [--interactive | -i] [--] ... +'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--] ... DESCRIPTION ----------- @@ -56,6 +56,10 @@ OPTIONS Add modified contents in the working tree interactively to the index. +-u:: + Update all files that git already knows about. This is what + "git commit -a" does in preparation for making a commit. + \--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken diff --git a/git-clean.html b/git-clean.html index 2688b3785..7ff3d73de 100644 --- a/git-clean.html +++ b/git-clean.html @@ -300,7 +300,7 @@ affected are further limited to those that match them.

- If the git configuration specifies clean.forceRequire as true, + If the git configuration specifies clean.requireForce as true, git-clean will refuse to run unless given -f or -n.

@@ -353,7 +353,7 @@ affected are further limited to those that match them.

diff --git a/git-clean.txt b/git-clean.txt index 5aff026eb..e3252d59d 100644 --- a/git-clean.txt +++ b/git-clean.txt @@ -26,7 +26,7 @@ OPTIONS Remove untracked directories in addition to untracked files. -f:: - If the git configuration specifies clean.forceRequire as true, + If the git configuration specifies clean.requireForce as true, git-clean will refuse to run unless given -f or -n. -n:: diff --git a/git-cvsexportcommit.html b/git-cvsexportcommit.html index b4aa5c4fd..8e1af0980 100644 --- a/git-cvsexportcommit.html +++ b/git-cvsexportcommit.html @@ -284,7 +284,7 @@ See examples below.

unchanged and up to date in the CVS checkout, and it will not autocommit by default.

Supports file additions, removals, and commits that affect binary files.

-

If the commit is a merge commit, you must tell git-cvsapplycommit what parent +

If the commit is a merge commit, you must tell git-cvsexportcommit what parent should the changeset be done against.

OPTIONS

@@ -404,7 +404,7 @@ $ git-cherry cvshead myhead | sed -n 's/^+ //p' | xargs -l1 git-cvsexportcommit diff --git a/git-cvsexportcommit.txt b/git-cvsexportcommit.txt index 555b8234f..fd7f54093 100644 --- a/git-cvsexportcommit.txt +++ b/git-cvsexportcommit.txt @@ -25,7 +25,7 @@ by default. Supports file additions, removals, and commits that affect binary files. -If the commit is a merge commit, you must tell git-cvsapplycommit what parent +If the commit is a merge commit, you must tell git-cvsexportcommit what parent should the changeset be done against. OPTIONS diff --git a/git-ls-files.html b/git-ls-files.html index b004c72c4..c428a7abe 100644 --- a/git-ls-files.html +++ b/git-ls-files.html @@ -330,8 +330,8 @@ shown:

- Show ignored files in the output - Note the this also reverses any exclude list present. + Show ignored files in the output. + Note that this also reverses any exclude list present.

@@ -688,7 +688,7 @@ from getting ignored.

diff --git a/git-ls-files.txt b/git-ls-files.txt index 79e0b7b71..076cebca1 100644 --- a/git-ls-files.txt +++ b/git-ls-files.txt @@ -42,8 +42,8 @@ OPTIONS Show other files in the output -i|--ignored:: - Show ignored files in the output - Note the this also reverses any exclude list present. + Show ignored files in the output. + Note that this also reverses any exclude list present. -s|--stage:: Show stage files in the output diff --git a/git-update-index.html b/git-update-index.html index b418ad003..d25f189d7 100644 --- a/git-update-index.html +++ b/git-update-index.html @@ -290,6 +290,8 @@ git-update-index(1) Manual Page

Modifies the index or directory cache. Each file mentioned is updated into the index and any unmerged or needs updating state is cleared.

+

See also git-add(1) for a more user-friendly way to do some of +the most common operations on the index.

The way "git-update-index" handles files it is told about can be modified using the various options:

@@ -702,7 +704,8 @@ from symbolic link to regular file.

See Also

Author

@@ -718,7 +721,7 @@ from symbolic link to regular file.

diff --git a/git-update-index.txt b/git-update-index.txt index cd5e014d4..6cfbd9a84 100644 --- a/git-update-index.txt +++ b/git-update-index.txt @@ -27,6 +27,9 @@ Modifies the index or directory cache. Each file mentioned is updated into the index and any 'unmerged' or 'needs updating' state is cleared. +See also gitlink:git-add[1] for a more user-friendly way to do some of +the most common operations on the index. + The way "git-update-index" handles files it is told about can be modified using the various options: @@ -306,7 +309,8 @@ The command looks at `core.ignorestat` configuration variable. See See Also -------- -gitlink:git-config[1] +gitlink:git-config[1], +gitlink:git-add[1] Author diff --git a/git.html b/git.html index 382b27e52..1aeb04d66 100644 --- a/git.html +++ b/git.html @@ -284,10 +284,9 @@ and full access to internals.

See this tutorial to get started, then see Everyday Git for a useful minimum set of commands, and "man git-commandname" for documentation of each command. CVS users may -also want to read CVS migration. -Git User's Manual is still work in -progress, but when finished hopefully it will guide a new user -in a coherent way to git enlightenment ;-).

+also want to read CVS migration. See +Git User's Manual for a more in-depth +introduction.

The COMMAND is either a name of a Git command (see below) or an alias as defined in the configuration file (see git-config(1)).

Formatted and hyperlinked version of the latest git @@ -2334,7 +2333,7 @@ contributors on the git-list <git@vger.kernel.org>.

diff --git a/git.txt b/git.txt index b0550b8b1..f84728bc1 100644 --- a/git.txt +++ b/git.txt @@ -21,10 +21,9 @@ and full access to internals. See this link:tutorial.html[tutorial] to get started, then see link:everyday.html[Everyday Git] for a useful minimum set of commands, and "man git-commandname" for documentation of each command. CVS users may -also want to read link:cvs-migration.html[CVS migration]. -link:user-manual.html[Git User's Manual] is still work in -progress, but when finished hopefully it will guide a new user -in a coherent way to git enlightenment ;-). +also want to read link:cvs-migration.html[CVS migration]. See +link:user-manual.html[Git User's Manual] for a more in-depth +introduction. The COMMAND is either a name of a Git command (see below) or an alias as defined in the configuration file (see gitlink:git-config[1]). diff --git a/user-manual.html b/user-manual.html index 489debf16..43fc75dce 100644 --- a/user-manual.html +++ b/user-manual.html @@ -1,17 +1,17 @@ -Git User's Manual (for version 1.5.1 or newer)

Git User's Manual (for version 1.5.1 or newer)


Table of Contents

Preface
1. Git Quick Start
Creating a new repository
Managing branches
Exploring history
Making changes
Merging
Sharing your changes
Repository maintenance
2. Repositories and Branches
How to get a git repository
How to check out a different version of a project
Understanding History: Commits
Understanding history: commits, parents, and reachability
Understanding history: History diagrams
Understanding history: What is a branch?
Manipulating branches
Examining an old version without creating a new branch
Examining branches from a remote repository
Naming branches, tags, and other references
Updating a repository with git fetch
Fetching branches from other repositories
3. Exploring git history
How to use bisect to find a regression
Naming commits
Creating tags
Browsing revisions
Generating diffs
Viewing old file versions
Examples
Check whether two branches point at the same history
Find first tagged version including a given fix
4. Developing with git
Telling git your name
Creating a new repository
How to make a commit
Creating good commit messages
How to merge
Resolving a merge
Getting conflict-resolution help during a merge
Undoing a merge
Fast-forward merges
Fixing mistakes
Fixing a mistake with a new commit
Fixing a mistake by editing history
Checking out an old version of a file
Ensuring good performance
Ensuring reliability
Checking the repository for corruption
Recovering lost changes
5. Sharing development with others
Getting updates with git pull
Submitting patches to a project
Importing patches to a project
Setting up a public repository
Exporting a git repository via http
Exporting a git repository via the git protocol
Pushing changes to a public repository
Setting up a shared repository
Allow web browsing of a repository
Examples
6. Rewriting history and maintaining patch series
Creating the perfect patch series
Keeping a patch series up to date using git-rebase
Modifying a single commit
Reordering or selecting from a patch series
Other tools
Problems with rewriting history
7. Advanced branch management
Fetching individual branches
Understanding git history: fast-forwards
Forcing git fetch to do non-fast-forward updates
Configuring remote branches
8. Git internals
The Object Database
Blob Object
Tree Object
Commit Object
Trust
Tag Object
The "index" aka "Current Directory Cache"
The Workflow
working directory -> index
index -> object database
object database -> index
index -> working directory
Tying it all together
Examining the data
Merging multiple trees
Merging multiple trees, continued
How git stores objects efficiently: pack files
Dangling objects
9. GIT Glossary
10. Notes and todo list for this manual

Preface

This manual is designed to be readable by someone with basic unix +Git User's Manual (for version 1.5.1 or newer)

Git User's Manual (for version 1.5.1 or newer)


Table of Contents

Preface
1. Git Quick Start
Creating a new repository
Managing branches
Exploring history
Making changes
Merging
Sharing your changes
Repository maintenance
2. Repositories and Branches
How to get a git repository
How to check out a different version of a project
Understanding History: Commits
Understanding history: commits, parents, and reachability
Understanding history: History diagrams
Understanding history: What is a branch?
Manipulating branches
Examining an old version without creating a new branch
Examining branches from a remote repository
Naming branches, tags, and other references
Updating a repository with git fetch
Fetching branches from other repositories
3. Exploring git history
How to use bisect to find a regression
Naming commits
Creating tags
Browsing revisions
Generating diffs
Viewing old file versions
Examples
Check whether two branches point at the same history
Find first tagged version including a given fix
4. Developing with git
Telling git your name
Creating a new repository
How to make a commit
Creating good commit messages
How to merge
Resolving a merge
Getting conflict-resolution help during a merge
Undoing a merge
Fast-forward merges
Fixing mistakes
Fixing a mistake with a new commit
Fixing a mistake by editing history
Checking out an old version of a file
Ensuring good performance
Ensuring reliability
Checking the repository for corruption
Recovering lost changes
5. Sharing development with others
Getting updates with git pull
Submitting patches to a project
Importing patches to a project
Setting up a public repository
Exporting a git repository via http
Exporting a git repository via the git protocol
Pushing changes to a public repository
Setting up a shared repository
Allow web browsing of a repository
Examples
6. Rewriting history and maintaining patch series
Creating the perfect patch series
Keeping a patch series up to date using git-rebase
Modifying a single commit
Reordering or selecting from a patch series
Other tools
Problems with rewriting history
7. Advanced branch management
Fetching individual branches
git fetch and fast-forwards
Forcing git fetch to do non-fast-forward updates
Configuring remote branches
8. Git internals
The Object Database
Blob Object
Tree Object
Commit Object
Trust
Tag Object
The "index" aka "Current Directory Cache"
The Workflow
working directory -> index
index -> object database
object database -> index
index -> working directory
Tying it all together
Examining the data
Merging multiple trees
Merging multiple trees, continued
How git stores objects efficiently: pack files
Dangling objects
9. GIT Glossary
10. Notes and todo list for this manual

Preface

This manual is designed to be readable by someone with basic unix command-line skills, but no previous knowledge of git.

Chapter 1 gives a brief overview of git commands, without any explanation; you may prefer to skip to chapter 2 on a first reading.

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.

Chapter 4 explains how to do development with git, and chapter 5 how to share that development with others.

Further chapters cover more specialized topics.

Comprehensive reference documentation is available through the man -pages. For a command such as "git clone", just use

$ man git-clone

Chapter 1. Git Quick Start

This is a quick summary of the major commands; the following chapters -will explain how these work in more detail.

Creating a new repository

From a tarball:

$ tar xzf project.tar.gz
+pages. For a command such as "git clone", just use

$ man git-clone

Chapter 1. Git Quick Start

This is a quick summary of the major commands; the following chapters +will explain how these work in more detail.

Creating a new repository

From a tarball:

$ tar xzf project.tar.gz
$ cd project
$ git init
Initialized empty Git repository in .git/
$ git add .
$ git commit

From a remote repository:

$ git clone git://example.com/pub/project.git
-$ cd project

Managing branches

$ git branch         # list all branches in this repo
+$ cd project

Managing branches

$ 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"

Instead of basing new branch on current HEAD (the default), use:

$ git branch new test    # branch named "test"
@@ -35,7 +35,7 @@ $   Tracked remote branches
    master next ...
$ git fetch example             # update branches from example
-$ git branch -r                 # list all remote branches

Exploring history

$ gitk                      # visualize and browse history
+$ git branch -r                 # list all remote branches

Exploring history

$ gitk                      # visualize and browse history
$ git log                   # list all commits
$ git log src/              # ...modifying src/
$ git log v2.6.15..v2.6.16  # ...in v2.6.16, not in v2.6.15
@@ -57,7 +57,7 @@ Bisecting:                                 # test here, then:
$ git bisect good               # if this revision is good, or
$ git bisect bad                # if this revision is bad.
-                                # repeat until done.

Making changes

Make sure git knows who to blame:

$ cat >~/.gitconfig <<\EOF
+                                # repeat until done.

Making changes

Make sure git knows who to blame:

$ cat >>~/.gitconfig <<\EOF
[user]
        name = Your Name Comes Here
        email = you@yourdomain.example.com
@@ -66,16 +66,16 @@ commit:

$ $ git add b.txt    # new file
$ git rm c.txt     # old file
$ git commit

Or, prepare and create the commit in one step:

$ git commit d.txt # use latest content only of d.txt
-$ git commit -a    # use latest content of all tracked files

Merging

$ git merge test   # merge branch "test" into the current branch
+$ git commit -a    # use latest content of all tracked files

Merging

$ git merge test   # merge branch "test" into the current branch
$ git pull git://example.com/project.git master
                   # fetch and merge in remote branch
-$ git pull . test  # equivalent to git merge test

Sharing your changes

Importing or exporting patches:

$ git format-patch origin..HEAD # format a patch for each commit
+$ git pull . test  # equivalent to git merge test

Sharing your changes

Importing or exporting patches:

$ git format-patch origin..HEAD # format a patch for each commit
                                # in HEAD but not in origin
$ git am mbox # import patches from the mailbox "mbox"

Fetch a branch in a different git repository, then merge into the current branch:

$ git pull git://example.com/project.git theirbranch

Store the fetched branch into a local branch before merging into the current branch:

$ git pull git://example.com/project.git theirbranch:mybranch

After creating commits on a local branch, update the remote branch with your commits:

$ git push ssh://example.com/project.git mybranch:theirbranch

When remote and local branch are both named "test":

$ git push ssh://example.com/project.git test

Shortcut version for a frequently used remote repository:

$ git remote add example ssh://example.com/project.git
-$ git push example test

Repository maintenance

Check for corruption:

$ git fsck

Recompress, remove unused cruft:

$ git gc

Repository maintenance

Check for corruption:

$ git fsck

Recompress, remove unused cruft:

$ git gc

Chapter 2. Repositories and Branches

How to get a git repository

It will be useful to have a git repository to experiment with as you read this manual.

The best way to get one is by using the git-clone(1) 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 @@ -88,7 +88,7 @@ will only need to clone once.

The clone command creates a new directory na 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.

In most of the following, examples will be taken from one of the two -repositories above.

How to check out a different version of a project

Git is best thought of as a tool for storing the history of a +repositories above.

How to check out a different version of a project

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.

A single git repository may contain multiple branches. It keeps track @@ -119,7 +119,7 @@ branches, with an asterisk marking the currently checked-out branch:

$ git reset --hard v2.6.17

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.

Understanding History: Commits

Every change in the history of a project is represented by a commit. +carefully.

Understanding History: Commits

Every change in the history of a project is represented by a commit. The git-show(1) command shows the most recent commit on the current branch:

$ git show
commit 2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2
@@ -159,7 +159,7 @@ has that commit at all). Since the object name is computed as a hash over the contents of the commit, you are guaranteed that the commit can never change without its name also changing.

In fact, in Chapter 8, Git internals 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.

Understanding history: commits, parents, and reachability

Every commit (except the very first commit in a project) also has a +with a name that is a hash of its contents.

Understanding history: commits, parents, and reachability

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.

However, the commits do not form a simple list; git allows lines of @@ -172,20 +172,20 @@ command; running gitk now on a git repository and looking for merge commits will help understand how the git organizes history.

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.

Understanding history: History diagrams

We will sometimes represent git history using diagrams like the one +leading from commit Y to commit X.

Understanding history: History diagrams

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:

         o--o--o <-- Branch A
         /
  o--o--o <-- master
         \
          o--o--o <-- Branch B

If we need to talk about a particular commit, the character "o" may -be replaced with another letter or number.

Understanding history: What is a branch?

When we need to be precise, we will use the word "branch" to mean a line +be replaced with another letter or number.

Understanding history: What is a branch?

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".

However, when no confusion will result, we often just use the term -"branch" both for branches and for branch heads.

Manipulating branches

Creating, deleting, and modifying branches is quick and easy; here's +"branch" both for branches and for branch heads.

Manipulating branches

Creating, deleting, and modifying branches is quick and easy; here's a summary of the commands:

git branch
@@ -205,8 +205,8 @@ git branch <branch> <start-point> 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>
@@ -238,12 +238,11 @@ If HEAD is now at 427abfa... Linux v2.6.17

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:

$ 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.

Examining branches from a remote repository

The "master" branch that was created at the time you cloned is a copy +  master

In this case we say that the HEAD is "detached".

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 branches from a remote repository

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 @@ -267,11 +266,9 @@ The tag "v2.6.18" is short for "refs/tags/v2.6.18".

  • "origin/master" is short for "refs/remotes/origin/master".
  • 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.

    For the complete list of paths which git checks for references, and +exists a tag and a branch with the same name.

    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 references with the same shorthand name, see the "SPECIFYING REVISIONS" section of git-rev-parse(1).

    Updating a repository with git fetch

    Eventually the developer cloned from will do additional work in her @@ -279,7 +276,7 @@ repository, creating new commits and advancing the branches to point at the new commits.

    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.

    Fetching branches from other repositories

    You can also track branches from repositories other than the one you +"master" branch that was created for you on clone.

    Fetching branches from other repositories

    You can also track branches from repositories other than the one you cloned from, using git-remote(1):

    $ git remote add linux-nfs git://linux-nfs.org/pub/nfs-2.6.git
    $ git fetch linux-nfs
    * refs/remotes/linux-nfs/master: storing branch 'master' ...
    @@ -296,12 +293,12 @@ a new stanza:

    $ ...

    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 -git-config(1) for details.)

    Chapter 3. Exploring git history

    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.

    Git provides extremely flexible and fast tools for exploring the history of a project.

    We start with one specialized tool that is useful for finding the -commit that introduced a bug into a project.

    How to use bisect to find a regression

    Suppose version 2.6.18 of your project worked, but the version at +commit that introduced a bug into a project.

    How to use bisect to find a regression

    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 @@ -329,7 +326,7 @@ occasionally you may land on a commit that broke something unrelated; run

    $ git bisect visualize

    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:

    $ git reset --hard fb47ddb2db...

    then test, run "bisect good" or "bisect bad" as appropriate, and -continue.

    Naming commits

    We have seen several ways of naming commits already:

    • +continue.

    Naming commits

    We have seen several ways of naming commits already:

    • 40-hexdigit object name
    • branch name: refers to the commit at the head of the given @@ -359,11 +356,11 @@ which refers to the other branch that we're merging in to the current branch.

      The git-rev-parse(1) command is a low-level command that is occasionally useful for translating some name for a commit to the object name for that commit:

      $ git rev-parse origin
      -e05db0fd4f31dde7005f075a84f96b360d05984b

    Creating tags

    We can also create a tag to refer to a particular commit; after -running

    $ git tag stable-1 1b2e1d63ff

    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 git-tag(1) man -page for details.

    Browsing revisions

    The git-log(1) command can show lists of commits. On its +e05db0fd4f31dde7005f075a84f96b360d05984b

    Creating tags

    We can also create a tag to refer to a particular commit; after +running

    $ git tag stable-1 1b2e1d63ff

    You can use stable-1 to refer to the commit 1b2e1d63ff.

    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 git-tag(1) man page +for details.

    Browsing revisions

    The git-log(1) 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:

    $ git log v2.5..        # commits since (not reachable from) v2.5
    $ git log test..master  # commits reachable from master but not test
    @@ -379,15 +376,15 @@ commits since v2.5 which touch the Makefile or any file under fs:

    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.

    Generating diffs

    You can generate diffs between any two versions using +commits are listed in may be somewhat arbitrary.

    Generating diffs

    You can generate diffs between any two versions using git-diff(1):

    $ git diff master..test

    Sometimes what you want instead is a set of patches:

    $ git format-patch master..test

    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.

    Viewing old file versions

    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.

    Viewing old file versions

    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:

    $ git show v2.5:fs/locks.c

    Before the colon may be anything that names a commit, and after it -may be any path to a file tracked by git.

    Examples

    Check whether two branches point at the same history

    Suppose you want to check whether two branches point at the same point +may be any path to a file tracked by git.

    Examples

    Check whether two branches point at the same history

    Suppose you want to check whether two branches point at the same point in history.

    $ git diff origin..master

    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 @@ -396,7 +393,7 @@ e05db0fd4f31dde7005f075a84f96b360d05984b
    $ git rev-list master
    e05db0fd4f31dde7005f075a84f96b360d05984b

    Or you could recall that the … operator selects all commits contained reachable from either one reference or the other but not -both: so

    $ git log origin...master

    will return no commits when the two branches are equal.

    Find first tagged version including a given fix

    Suppose you know that the commit e05db0fd fixed a certain problem. +both: so

    $ git log origin...master

    will return no commits when the two branches are equal.

    Find first tagged version including a given fix

    Suppose you know that the commit e05db0fd fixed a certain problem. You'd like to find the earliest tagged release that contains that fix.

    Of course, there may be more than one answer—if the history branched after commit e05db0fd, then there could be multiple "earliest" tagged @@ -423,13 +420,12 @@ available
       ! [v1.5.0-rc2] GIT v1.5.0-rc2
    ...

    then search for a line that looks like

    + ++ [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if
    available

    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.

    Chapter 4. Developing with git

    Telling git your name

    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:

    [user]
            name = Your Name Comes Here
    -        email = you@yourdomain.example.com
    -EOF

    (See the "CONFIGURATION FILE" section of git-config(1) for -details on the configuration file.)

    Creating a new repository

    Creating a new repository from scratch is very easy:

    $ mkdir project
    +        email = you@yourdomain.example.com

    (See the "CONFIGURATION FILE" section of git-config(1) for +details on the configuration file.)

    Creating a new repository

    Creating a new repository from scratch is very easy:

    $ mkdir project
    $ cd project
    $ git init

    If you have some initial content (say, a tarball):

    $ tar -xzvf project.tar.gz
    $ cd project
    @@ -460,12 +456,14 @@ about to commit:

    $ $ git diff          # difference between the index file and your
                        # working directory; changes that would not
                        # be included if you ran "commit" now.
    -$ git status        # a brief per-file summary of the above.

    Creating good commit messages

    Though not required, it's a good idea to begin the commit message +$ 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

    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.

    How to merge

    You can rejoin two diverging branches of development using +body.

    How to merge

    You can rejoin two diverging branches of development using git-merge(1):

    $ git merge branchname

    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 @@ -478,7 +476,7 @@ you resolve the conflicts manually, you can update the index with the contents and run git commit, as you normally would when creating a new file.

    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.

    In more detail:

    Resolving a merge

    When a merge isn't resolved automatically, git leaves the index and +one to the top of the other branch.

    Resolving a merge

    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.

    Files with conflicts are marked specially in the index, so until you resolve the problem and update the index, git-commit(1) will @@ -493,7 +491,7 @@ $ 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.

    The above is all you need to know to resolve a simple merge. But git -also provides more information to help resolve conflicts:

    Getting conflict-resolution help during a merge

    All of the changes that git was able to merge automatically are +also provides more information to help resolve conflicts:

    Getting conflict-resolution help during a merge

    All of the changes that git was able to merge automatically are already added to the index file, so git-diff(1) shows only the conflicts. It uses an unusual syntax:

    $ git diff
    diff --cc file.txt
    @@ -542,20 +540,20 @@ $ $ git diff --theirs file.txt    # same as the above.

    The git-log(1) and gitk[1] commands also provide special help for merges:

    $ git log --merge
    $ gitk --merge

    These will display all commits which exist only on HEAD or on -MERGE_HEAD, and which touch an unmerged file.

    Each time you resolve the conflicts in a file and update the index:

    $ git add file.txt

    the different stages of that file will be "collapsed", after which +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:

    $ git add file.txt

    the different stages of that file will be "collapsed", after which git-diff will (by default) no longer show diffs for that file.

    Undoing a merge

    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

    $ git reset --hard HEAD

    Or, if you've already commited the merge that you want to throw away,

    $ git reset --hard ORIG_HEAD

    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.

    Fast-forward merges

    There is one special case not mentioned above, which is treated +further merges.

    Fast-forward merges

    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.

    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 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

    If you've messed up the working tree, but haven't yet committed your +were merged.

    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

    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

    $ git reset --hard HEAD

    If you make a commit that you later wish you hadn't, there are two fundamentally different ways to fix the problem:

    1. @@ -568,7 +566,7 @@ You can go back and modify the old commit. You should 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. -

    Fixing a mistake with a new commit

    Creating a new commit that reverts an earlier change is very easy; +

    Fixing a mistake with a new commit

    Creating a new commit that reverts an earlier change is very easy; just pass the git-revert(1) command a reference to the bad commit; for example, to revert the most recent commit:

    $ git revert HEAD

    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.

    You can also revert an earlier change, for example, the next-to-last:

    $ git revert HEAD^

    In this case git will attempt to undo the old change while leaving @@ -583,17 +581,17 @@ changes, giving you a chance to edit the old commit message first.

    Again, been merged into another branch; use git-revert(1) instead in that case.

    It is also possible to edit commits further back in the history, but this is an advanced topic to be left for -another chapter.

    Checking out an old version of a file

    In the process of undoing a previous bad change, you may find it +another chapter.

    Checking out an old version of a file

    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 git-checkout(1). We've used git checkout before to switch branches, but it has quite different behavior if it is given a path name: the command

    $ git checkout HEAD^ path/to/file

    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.

    If you just want to look at an old version of the file, without modifying the working directory, you can do that with -git-show(1):

    $ git show HEAD^:path/to/file

    which will display the given version of the file.

    Ensuring good performance

    On large repositories, git depends on compression to keep the history +git-show(1):

    $ git show HEAD^:path/to/file

    which will display the given version of the file.

    Ensuring good performance

    On large repositories, git depends on compression to keep the history information from taking up to much space on disk or in memory.

    This compression is not performed automatically. Therefore you should occasionally run git-gc(1):

    $ git gc

    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

    Checking the repository for corruption

    The git-fsck(1) command runs a number of self-consistency checks +you may prefer to run git-gc when you are not doing other work.

    Ensuring reliability

    Checking the repository for corruption

    The git-fsck(1) 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:

    $ git fsck
    dangling commit 7281251ddd2a61e38657c827739c57015671a6b3
    @@ -604,11 +602,13 @@ dangling dangling commit 8e4bec7f2ddaa268bef999853c25755452100f8e
    dangling tree d50bb86186bf27b681d25af89d3b5b68382e4085
    dangling tree b24c2473f1fd3d91352a624795be026d64c8841f
    -...

    Dangling objects are objects that are harmless, but also unnecessary; -you can remove them at any time with 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 the section called “Dangling objects” for details. However, if +you want, you may remove them with git-prune(1) or the —prune option to git-gc(1):

    $ git gc --prune

    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.

    For more about dangling objects, see the section called “Dangling objects”.

    Recovering lost changes

    Reflogs

    Say you modify a branch with git-reset(1) —hard, and then +other git operations are in progress in the same repository.

    Recovering lost changes

    Reflogs

    Say you modify a branch with git-reset(1) —hard, and then realize that the branch was the only reference you had to that point in history.

    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 @@ -617,18 +617,21 @@ This syntax can be used to with any git command that accepts a commit, not just with git log. Some other examples:

    $ git show master@{2}           # See where the branch pointed 2,
    $ git show master@{3}           # 3, ... changes ago.
    $ gitk master@{yesterday}       # See where it pointed yesterday,
    -$ gitk master@{"1 week ago"}    # ... or last week

    The reflogs are kept by default for 30 days, after which they may be +$ 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 git-reflog(1) and git-gc(1) to learn how to control this pruning, and see the "SPECIFYING REVISIONS" section of git-rev-parse(1) for details.

    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.

    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":

    $ git fsck
    +how the branches in your local repository have changed over time.

    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 in the dangling objects that git-fsck reports. See +the section called “Dangling objects” for the details.

    $ git fsck
    dangling commit 7281251ddd2a61e38657c827739c57015671a6b3
    dangling commit 2706a059f258c6b245f298dc4ff2ccd30ec21a63
    dangling commit 13472b7c4b80851a1bc551779171dcb03655e9b5
    @@ -640,7 +643,8 @@ you get exactly the history reachable from that commit that is lost. (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.)

    If you decide you want the history back, you can always create a new -reference pointing to it, for example, a new branch:

    $ git branch recovered-branch 7281251ddd

    Chapter 5. Sharing development with others

    Getting updates with git pull

    After you clone a repository and make a few changes of your own, you +reference pointing to it, for example, a new branch:

    $ git branch recovered-branch 7281251ddd

    Other types of dangling objects (blobs and trees) are also possible, and +dangling objects can arise in other situations.

    Chapter 5. Sharing development with others

    Getting updates with git pull

    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.

    We have already seen how to keep remote tracking branches up to date with git-fetch(1), and how to merge two branches. So you can merge in changes from the @@ -648,22 +652,25 @@ original repository's master branch with:

    $ $ git merge origin/master

    However, the git-pull(1) command provides a way to do this in one step:

    $ git pull origin master

    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

    $ git pull

    See the descriptions of the branch.<name>.remote and -branch.<name>.merge options in git-config(1) to learn -how to control these defaults depending on the current branch.

    In addition to saving you keystrokes, "git pull" also helps you by +so often you can accomplish the above with just

    $ git pull

    See the descriptions of the branch.<name>.remote and branch.<name>.merge +options in git-config(1) to learn how to control these defaults +depending on the current branch. Also note that the —track option to +git-branch(1) and 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 repository that you pulled from.

    (But note that no such commit will be created in the case of a -fast forward; instead, your branch will just be +fast forward; instead, your branch will just be updated to point to the latest commit from the upstream branch.)

    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

    $ git pull . branch
    -$ git merge branch

    are roughly equivalent. The former is actually very commonly used.

    Submitting patches to a project

    If you just have a few changes, the simplest way to submit them may +$ git merge branch

    are roughly equivalent. The former is actually very commonly used.

    Submitting patches to a project

    If you just have a few changes, the simplest way to submit them may just be to send them as patches in email:

    First, use git-format-patch(1); for example:

    $ git format-patch origin

    will produce a numbered series of files in the current directory, one for each patch in the current branch but not in origin/HEAD.

    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 git-send-email(1) script to automate the process. Consult the mailing list for your project first to determine how they -prefer such patches be handled.

    Importing patches to a project

    Git also provides a tool called git-am(1) (am stands for +prefer such patches be handled.

    Importing patches to a project

    Git also provides a tool called git-am(1) (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

    $ git am -3 patches.mbox

    Git will apply each patch in order; if any conflicts are found, it @@ -699,9 +706,9 @@ your personal repo ------------------> your public repo | | | they push V their public repo <------------------- their repo

    Now, assume your personal repository is in the directory ~/proj. We -first create a new clone of the repository:

    $ git clone --bare proj-clone.git

    The resulting directory proj-clone.git will contains a "bare" git +first create a new clone of the repository:

    $ git clone --bare proj.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 +a checked-out copy of a working directory.

    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.

    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 @@ -711,7 +718,7 @@ host with a web server set up, http exports may be simpler to set up.

    All a directory that is exported by the web server, and make some adjustments to give web clients some extra information they need:

    $ 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

    (For an explanation of the last two lines, see git-update-server-info(1), and the documentation Hooks used by git.)

    Advertise the url of proj.git. Anybody else should then be able to @@ -726,25 +733,25 @@ access, which you will need to update the public repository with the latest changes created in your private repository.

    The simplest way to do this is using git-push(1) and ssh; to update the remote branch named "master" with the latest state of your branch named "master", run

    $ git push ssh://yourserver.com/~you/proj.git master:master

    or just

    $ git push ssh://yourserver.com/~you/proj.git master

    As with git-fetch, git-push will complain if this does not result in -a fast forward. Normally this is a sign of +a fast forward. 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:

    $ git push ssh://yourserver.com/~you/proj.git +master

    As with git-fetch, you may also set up configuration options to -save typing; so, for example, after

    $ cat >.git/config <<EOF
    +save typing; so, for example, after

    $ cat >>.git/config <<EOF
    [remote "public-repo"]
            url = ssh://yourserver.com/~you/proj.git
    EOF

    you should be able to perform the above push with just

    $ git push public-repo master

    See the explanations of the remote.<name>.url, branch.<name>.remote, and remote.<name>.push options in git-config(1) for -details.

    Setting up a shared repository

    Another way to collaborate is by using a model similar to that +details.

    Setting up a shared repository

    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 git for CVS users for instructions on how to -set this up.

    Allow web browsing of a repository

    The gitweb cgi script provides users an easy way to browse your +set this up.

    Allow web browsing of a repository

    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.

    Examples

    TODO: topic branches, typical roles as in everyday.txt, ?

    Chapter 6. Rewriting history and maintaining patch series

    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.

    Examples

    TODO: topic branches, typical roles as in everyday.txt, ?

    Chapter 6. Rewriting history and maintaining patch series

    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.

    However, there is a situation in which it can be useful to violate this -assumption.

    Creating the perfect patch series

    Suppose you are a contributor to a large project, and you want to add a +assumption.

    Creating the perfect patch series

    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.

    If you present all of your changes as a single patch (or commit), they @@ -763,7 +770,7 @@ The complete series produces the same end result as your own (probably much messier!) development process did.

    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.

    Keeping a patch series up to date using git-rebase

    Suppose that you create a branch "mywork" on a remote-tracking branch +you are rewriting history.

    Keeping a patch series up to date using git-rebase

    Suppose that you create a branch "mywork" on a remote-tracking branch "origin", and create some commits on top of it:

    $ git checkout -b mywork origin
    $ vi file.txt
    $ git commit
    @@ -790,7 +797,7 @@ patches to the new mywork. The result will look like:

    $ git rebase --continue

    and git will continue applying the rest of the patches.

    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:

    $ git rebase --abort

    Modifying a single commit

    We saw in the section called “Fixing a mistake by editing history” that you can replace the +return mywork to the state it had before you started the rebase:

    $ git rebase --abort

    Modifying a single commit

    We saw in the section called “Fixing a mistake by editing history” that you can replace the most recent commit using

    $ git commit --amend

    which will replace the old commit by a new commit incorporating your changes, giving you a chance to edit the old commit message first.

    You can also use a combination of this and git-rebase(1) to edit commits further back in your history. First, tag the problematic commit with

    $ git tag bad mywork~5

    (Either gitk or git-log may be useful for finding the commit.)

    Then check out that commit, edit it, and rebase the rest of the series @@ -802,7 +809,7 @@ $ patches on mywork reapplied on top of your modified commit. You can then clean up with

    $ git tag -d bad

    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.

    Reordering or selecting from a patch series

    Given one existing commit, the git-cherry-pick(1) command +new commits having new object names.

    Reordering or selecting from a patch series

    Given one existing commit, the git-cherry-pick(1) 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:

    $ git checkout -b mywork-new origin
    @@ -812,9 +819,9 @@ cherry-pick, and possibly modifying them as you go using commit —amend.

    Another technique is to use git-format-patch to create a series of patches, then reset the state to before the patches:

    $ git format-patch origin
    $ git reset --hard origin

    Then modify, reorder, or eliminate patches as preferred before applying -them again with git-am(1).

    Other tools

    There are numerous other tools, such as stgit, which exist for the +them again with git-am(1).

    Other tools

    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.

    Problems with rewriting history

    The primary problem with rewriting the history of a branch has to do +this manual.

    Problems with rewriting history

    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:

     o--o--O--o--o--o <-- origin
             \        \
    @@ -835,7 +842,7 @@ new.  The results are likely to be unexpected.

    You may still choose to pub 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.

    For true distributed development that supports proper merging, -published branches should never be rewritten.

    Chapter 7. Advanced branch management

    Fetching individual branches

    Instead of using git-remote(1), you can also choose just +published branches should never be rewritten.

    Chapter 7. Advanced branch management

    Fetching individual branches

    Instead of using git-remote(1), you can also choose just to update one branch at a time, and to store it locally under an arbitrary name:

    $ git fetch origin todo:my-todo-work

    The first argument, "origin", just tells git to fetch from the repository you originally cloned from. The second argument tells git @@ -843,12 +850,12 @@ to fetch the branch named "todo" from the remote repository, and to store it locally under the name refs/heads/my-todo-work.

    You can also fetch branches from other repositories; so

    $ git fetch git://example.com/proj.git master:example-master

    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:

    Understanding git history: fast-forwards

    In the previous example, when updating an existing branch, "git +fast-forward to the commit given by example.com's +master branch. In more detail:

    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".

    A fast forward looks something like this:

     o--o--o--o <-- old head of the branch
    +commit.  Git calls this process a fast forward.

    A fast forward looks something like this:

     o--o--o--o <-- old head of the branch
                \
                 o--o--o <-- new head of the branch

    In some cases it is possible that the new head will not actually be a descendant of the old head. For example, the developer may have @@ -859,10 +866,10 @@ resulting in a situation like:

     o--o--o--o--a--b &
     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.

    Forcing git fetch to do non-fast-forward updates

    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:

    $ 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.

    Configuring remote branches

    We saw above that "origin" is just a shortcut to refer to the +them.

    Forcing git fetch to do non-fast-forward updates

    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:

    $ git fetch git://example.com/proj.git +master:refs/remotes/example/master

    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.

    Configuring remote branches

    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 git-config(1):

    $ git config -l
    @@ -882,12 +889,12 @@ $ throwing away commits on mybranch.

    Also note that all of the above configuration can be performed by directly editing the file .git/config instead of using git-config(1).

    See git-config(1) for more details on the configuration -options mentioned above.

    Chapter 8. Git internals

    Git depends on two fundamental abstractions: the "object database", and -the "current directory cache" aka "index".

    The Object Database

    The object database is literally just a content-addressable collection +options mentioned above.

    Chapter 8. Git internals

    Git depends on two fundamental abstractions: the "object database", and +the "current directory cache" aka "index".

    The Object Database

    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.

    All objects have a statically determined "type" aka "tag", which is +build up a hierarchy of objects.

    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", @@ -902,7 +909,7 @@ together into a directed acyclic graph of revisions - eac 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.

    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 @@ -927,7 +934,7 @@ size> + <byte\0> + <binary object data>.

    The structured obj connectivity to other objects verified. This is generally done with the git-fsck 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).

    The object types in some more detail:

    Blob Object

    A "blob" object is nothing but a binary blob of data, and doesn't +to just verifying their superficial consistency through the hash).

    The object types in some more detail:

    Blob Object

    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 is indexed by its sha1 hash, so the data itself is certainly correct), it @@ -939,7 +946,7 @@ repository) have the same contents, they will share the same blob 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.

    A blob is typically created when git-update-index(1) -is run, and its data can be accessed by git-cat-file(1).

    Tree Object

    The next hierarchical object type is the "tree" object. A tree object +is run, and its data can be accessed by git-cat-file(1).

    Tree Object

    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.

    Like the "blob" object, a tree object is uniquely determined by the @@ -963,7 +970,7 @@ involved), you can see trivial renames or permission changes by noticing that the blob stayed the same. However, renames with data changes need a smarter "diff" implementation.

    A tree is created with git-write-tree(1) and its data can be accessed by git-ls-tree(1). -Two trees can be compared with git-diff-tree(1).

    Commit Object

    The "commit" object is an object that introduces the notion of +Two trees can be compared with git-diff-tree(1).

    Commit Object

    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.

    A "commit" is defined by the tree-object that it results in, the @@ -973,12 +980,12 @@ the contents are well-defined and "safe" due to the cryptographically 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.

    Note on commits: unlike real SCM's, commits do not contain +result, for example.

    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.

    A commit is created with git-commit-tree(1) and -its data can be accessed by git-cat-file(1).

    Trust

    An aside on the notion of "trust". Trust is really outside the scope +its data can be accessed by git-cat-file(1).

    Trust

    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 can trust that an object is intact and has not been messed with by external sources. So the name @@ -994,7 +1001,7 @@ that you trust that commit, and the immutability of the history of commits tells others that they can trust the whole history.

    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.

    To assist in this, git also provides the tag object…

    Tag Object

    Git provides the "tag" object to simplify creating, managing and +like GPG/PGP.

    To assist in this, git also provides the tag object…

    Tag Object

    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.

    However it can optionally contain additional signature information @@ -1004,8 +1011,8 @@ integrity; the trust framework (and signature provision and verification) has to come from outside.

    A tag is created with git-mktag(1), its data can be accessed by git-cat-file(1), and the signature can be verified by -git-verify-tag(1).

    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 +git-verify-tag(1).

    The "index" aka "Current Directory Cache"

    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 @@ -1037,11 +1044,11 @@ involves a controlled modification of the index file. In particular, 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.

    The Workflow

    Generally, all "git" operations work on the index file. Some operations +been written back to the backing store.

    The Workflow

    Generally, all "git" operations work on the index file. Some operations work purely 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:

    working directory -> index

    You update the index with information from the working directory with +main combinations:

    working directory -> index

    You update the index with information from the working directory with the git-update-index(1) command. You generally update the index information by just specifying the filename you want to update, like so:

    $ git-update-index filename

    but to avoid common mistakes with filename globbing etc, the command @@ -1057,16 +1064,16 @@ does not exist any more, it will update the index accordingly.

    As a specia will refresh the "stat" information of each index to match the current stat information. It will not 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.

    index -> object database

    You write your current index file to a "tree" object with the program

    $ git-write-tree

    that doesn't come with any options - it will just write out the +an object still matches its old backing store object.

    index -> object database

    You write your current index file to a "tree" object with the program

    $ git-write-tree

    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:

    object database -> index

    You read a "tree" file from the object database, and use that to +other direction:

    object database -> index

    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

    $ git-read-tree <sha1 of tree>

    and your index file will now be equivalent to the tree that you saved earlier. However, that is only your index file: your working -directory contents have not been modified.

    index -> working directory

    You update your working directory from the index by "checking out" +directory contents have not been modified.

    index -> working directory

    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 @@ -1077,7 +1084,7 @@ with

    $ if you have an old version of the tree already checked out, you will need to use the "-f" flag (before the "-a" flag or the filename) to force the checkout.

    Finally, there are a few odds and ends which are not purely moving -from one representation to the other:

    Tying it all together

    To commit a tree you have instantiated with "git-write-tree", you'd +from one representation to the other:

    Tying it all together

    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.

    Normally a "commit" has one parent: the previous state of the tree @@ -1126,7 +1133,7 @@ various pieces fit together.


                        |  Working  |
                        | Directory |
                        +-----------+
    -

    Examining the data

    You can examine the data represented in the object database and the +

    Examining the data

    You can examine the data represented in the object database and the index with various helper tools. For every object, you can use git-cat-file(1) to examine details about the object:

    $ git-cat-file -t <objectname>

    shows the type of the object, and once you have the type (which is @@ -1136,7 +1143,7 @@ there is a special helper for showing that content, called readable form.

    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 .git/HEAD, -you can do

    $ git-cat-file commit HEAD

    to see what the top commit was.

    Merging multiple trees

    Git helps you do a three-way merge, which you can expand to n-way by +you can do

    $ git-cat-file commit HEAD

    to see what the top commit was.

    Merging multiple trees

    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 @@ -1148,14 +1155,14 @@ of two commits with

    $ now look up the "tree" objects of those commits, which you can easily do with (for example)

    $ git-cat-file commit <commitname> | head -1

    since the tree object information is always the first line in a commit 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 always do a merge against your last commit (which should thus match what you have in your current index anyway).

    To do the merge, do

    $ git-read-tree -m -u <origtree> <yourtree> <targettree>

    which will do all trivial merge operations for you directly in the index file, and you can just write the result out with -git-write-tree.

    Merging multiple trees, continued

    Sadly, many merges aren't trivial. If there are files that have +git-write-tree.

    Merging multiple trees, continued

    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 NOT be written out to a tree @@ -1177,11 +1184,11 @@ obviously the final outcome is what is in HEAD. Wh 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:

    $ git-cat-file blob 263414f... >hello.c~1
    +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

    This would leave the merge result in hello.c~2 file, along +$ git merge-file hello.c~2 hello.c~1 hello.c~3

    This would leave the merge result in hello.c~2 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:

    $ mv -f hello.c~2 hello.c
    @@ -1190,7 +1197,7 @@ that path tells git to mark the path resolved.

    The above is the descriptio to help you understand what conceptually happens under the hood. In practice, nobody, not even git itself, uses three git-cat-file for this. There is git-merge-index program that extracts the -stages to temporary files and calls a "merge" script on it:

    $ git-merge-index git-merge-one-file hello.c

    and that is what higher level git merge -s resolve is implemented with.

    How git stores objects efficiently: pack files

    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:

    $ git-merge-index git-merge-one-file hello.c

    and that is what higher level git merge -s resolve is implemented with.

    How git stores objects efficiently: pack files

    We've seen how git stores each object in a file named after the object's SHA1 hash.

    Unfortunately this system becomes inefficient once a project has a lot of objects. Try this on an old project:

    $ git count-objects
    6930 objects, 47620 kilobytes

    The first number is the number of objects which are kept in @@ -1217,9 +1224,8 @@ you, so is normally the only high-level command you need.

    Chapter 6, Rewriting history and maintaining patch series. 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.

    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.

    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 @@ -1235,9 +1241,10 @@ up pointing to them, so they end up "dangling" in your repository.

    General 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).

    For commits, the most useful thing to do with dangling objects tends to -be to do a simple

    $ 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

    $ git show <dangling-blob/tree-sha-goes-here>

    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).

    For commits, you can just use:

    $ gitk <dangling-commit-sha-goes-here> --not --all

    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>

    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.

    Usually, dangling blobs and trees aren't very interesting. They're almost always the result of either being a half-way mergebase (the blob @@ -1254,7 +1261,7 @@ on what it found, git-fsck itself is never "dangerous" to run. 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 BAD idea).

    Chapter 9. GIT Glossary

    +repository is a BAD idea).

    Chapter 9. GIT Glossary

    alternate object database
    Via the alternates mechanism, a repository can @@ -1719,7 +1726,7 @@ repository is a BAD idea).

    The set of files and directories currently being worked on, i.e. you can work in your working tree without using git at all. -

    Chapter 10. Notes and todo list for this manual

    This is a work in progress.

    The basic requirements: +

    Chapter 10. Notes and todo list for this manual

    This is a work in progress.

    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 diff --git a/user-manual.txt b/user-manual.txt index dff438f76..67f5b9b6a 100644 --- a/user-manual.txt +++ b/user-manual.txt @@ -23,12 +23,14 @@ pages. For a command such as "git clone", just use $ 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 ------------------------- @@ -50,11 +52,12 @@ $ git clone git://example.com/pub/project.git $ 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" @@ -112,6 +115,7 @@ $ git branch -r # list all remote branches ----------------------------------------------- +[[exploring-history]] Exploring history ----------------- @@ -147,13 +151,14 @@ $ git bisect bad # if this revision is bad. # 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 @@ -177,6 +182,7 @@ $ git commit d.txt # use latest content only of d.txt $ git commit -a # use latest content of all tracked files ----------------------------------------------- +[[merging]] Merging ------- @@ -187,6 +193,7 @@ $ git pull git://example.com/project.git master $ git pull . test # equivalent to git merge test ----------------------------------------------- +[[sharing-your-changes]] Sharing your changes -------------------- @@ -232,6 +239,7 @@ $ git remote add example ssh://example.com/project.git $ git push example test ----------------------------------------------- +[[repository-maintenance]] Repository maintenance ---------------------- @@ -247,9 +255,11 @@ Recompress, remove unused cruft: $ git gc ----------------------------------------------- +[[repositories-and-branches]] Repositories and Branches ========================= +[[how-to-get-a-git-repository]] How to get a git repository --------------------------- @@ -280,6 +290,7 @@ contains all the information about the history of the project. 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 ------------------------------------------------- @@ -352,6 +363,7 @@ 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. +[[understanding-commits]] Understanding History: Commits ------------------------------ @@ -407,6 +419,7 @@ In fact, in <> 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. +[[understanding-reachability]] Understanding history: commits, parents, and reachability ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -431,6 +444,7 @@ 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. +[[history-diagrams]] Understanding history: History diagrams ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -450,6 +464,7 @@ lines drawn with - / and \. Time goes left to right: 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -463,6 +478,7 @@ the line of three commits leading up to that point as all being part of However, when no confusion will result, we often just use the term "branch" both for branches and for branch heads. +[[manipulating-branches]] Manipulating branches --------------------- @@ -480,8 +496,8 @@ git branch :: including using a branch name or a tag name git branch -d :: delete the 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 :: even if the branch points to a commit not reachable from the current branch, you may know that that commit @@ -527,18 +543,18 @@ and git branch shows that you are no longer on a branch: ------------------------------------------------ $ 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 ------------------------------------------- @@ -586,13 +602,9 @@ shorthand: 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 @@ -612,6 +624,7 @@ 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. +[[fetching-branches]] Fetching branches from other repositories ----------------------------------------- @@ -654,6 +667,7 @@ or delete these configuration options by editing .git/config with a text editor. (See the "CONFIGURATION FILE" section of gitlink:git-config[1] for details.) +[[exploring-git-history]] Exploring git history ===================== @@ -668,6 +682,7 @@ history of a project. 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 -------------------------------------- @@ -735,6 +750,7 @@ $ git reset --hard fb47ddb2db... then test, run "bisect good" or "bisect bad" as appropriate, and continue. +[[naming-commits]] Naming commits -------------- @@ -799,6 +815,7 @@ $ git rev-parse origin e05db0fd4f31dde7005f075a84f96b360d05984b ------------------------------------------------- +[[creating-tags]] Creating tags ------------- @@ -811,11 +828,12 @@ $ git tag stable-1 1b2e1d63ff 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 ------------------ @@ -857,6 +875,7 @@ 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. +[[generating-diffs]] Generating diffs ---------------- @@ -878,6 +897,7 @@ 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. +[[viewing-old-file-versions]] Viewing old file versions ------------------------- @@ -893,9 +913,11 @@ $ git show v2.5:fs/locks.c 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -928,6 +950,7 @@ $ git log origin...master will return no commits when the two branches are equal. +[[finding-tagged-descendants]] Find first tagged version including a given fix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1013,27 +1036,29 @@ 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. +[[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 ------------------------- @@ -1147,9 +1172,12 @@ $ git diff --cached # difference between HEAD and the index; what $ 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 ----------------------------- @@ -1160,6 +1188,7 @@ 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. +[[how-to-merge]] How to merge ------------ @@ -1192,8 +1221,6 @@ 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. -In more detail: - [[resolving-a-merge]] Resolving a merge ----------------- @@ -1237,6 +1264,7 @@ your own if desired. 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1329,6 +1357,9 @@ $ gitk --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: ------------------------------------------------- @@ -1360,6 +1391,7 @@ 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. +[[fast-forwards]] Fast-forward merges ------------------- @@ -1368,13 +1400,13 @@ 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. -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 -<>; 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 --------------- @@ -1399,6 +1431,7 @@ fundamentally different ways to fix the problem: 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1453,6 +1486,7 @@ It is also possible to edit commits further back in the history, but this is an advanced topic to be left for <>. +[[checkout-of-path]] Checking out an old version of a file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1479,6 +1513,7 @@ $ git show HEAD^:path/to/file which will display the given version of the file. +[[ensuring-good-performance]] Ensuring good performance ------------------------- @@ -1495,9 +1530,12 @@ $ git gc 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1518,8 +1556,10 @@ dangling tree b24c2473f1fd3d91352a624795be026d64c8841f ... ------------------------------------------------- -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 <> for details. However, if +you want, you may remove them with gitlink:git-prune[1] or the --prune option to gitlink:git-gc[1]: ------------------------------------------------- @@ -1530,12 +1570,11 @@ 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. -For more about dangling objects, see <>. - - +[[recovering-lost-changes]] Recovering lost changes ~~~~~~~~~~~~~~~~~~~~~~~ +[[reflogs]] Reflogs ^^^^^^^ @@ -1560,8 +1599,19 @@ $ git show master@{2} # See where the branch pointed 2, $ 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" @@ -1572,15 +1622,16 @@ 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. +[[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 +<> for the details. ------------------------------------------------- $ git fsck @@ -1612,7 +1663,11 @@ reference pointing to it, for example, a new branch: $ 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 =============================== @@ -1649,9 +1704,16 @@ so often you can accomplish the above with just $ git pull ------------------------------------------------- -See the descriptions of the branch..remote and -branch..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..remote and branch..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 @@ -1672,6 +1734,7 @@ $ git merge branch are roughly equivalent. The former is actually very commonly used. +[[submitting-patches]] Submitting patches to a project ------------------------------- @@ -1693,6 +1756,7 @@ use the gitlink:git-send-email[1] script to automate the process. Consult the mailing list for your project first to determine how they prefer such patches be handled. +[[importing-patches]] Importing patches to a project ------------------------------ @@ -1772,14 +1836,14 @@ Now, assume your personal repository is in the directory ~/proj. We 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. @@ -1805,7 +1869,7 @@ adjustments to give web clients some extra information they need: ------------------------------------------------- $ 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 ------------------------------------------------- @@ -1872,7 +1936,7 @@ As with git-fetch, you may also set up configuration options to save typing; so, for example, after ------------------------------------------------- -$ cat >.git/config <>.git/config <.url, branch..remote, and remote..push options in gitlink:git-config[1] for details. +[[setting-up-a-shared-repository]] Setting up a shared repository ------------------------------ @@ -1897,6 +1962,7 @@ all push to and pull from a single shared repository. See 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 ---------------------------------- @@ -1904,6 +1970,7 @@ 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. +[[sharing-development-examples]] Examples -------- @@ -1921,6 +1988,7 @@ cause git's merge machinery (for example) to do the wrong thing. However, there is a situation in which it can be useful to violate this assumption. +[[patch-series]] Creating the perfect patch series --------------------------------- @@ -1953,6 +2021,7 @@ 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. +[[using-git-rebase]] Keeping a patch series up to date using git-rebase -------------------------------------------------- @@ -2034,6 +2103,7 @@ return mywork to the state it had before you started the rebase: $ git rebase --abort ------------------------------------------------- +[[modifying-one-commit]] Modifying a single commit ------------------------- @@ -2079,6 +2149,7 @@ 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. +[[reordering-patch-series]] Reordering or selecting from a patch series ------------------------------------------- @@ -2108,6 +2179,7 @@ $ git reset --hard origin Then modify, reorder, or eliminate patches as preferred before applying them again with gitlink:git-am[1]. +[[patch-series-tools]] Other tools ----------- @@ -2115,6 +2187,7 @@ 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. +[[problems-with-rewriting-history]] Problems with rewriting history ------------------------------- @@ -2163,9 +2236,11 @@ branches into their own work. 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 ---------------------------- @@ -2191,18 +2266,18 @@ $ git fetch git://example.com/proj.git master:example-master 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: +<> 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 <>. A fast forward looks something like this: @@ -2232,6 +2307,7 @@ 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. +[[forcing-fetch]] Forcing git fetch to do non-fast-forward updates ------------------------------------------------ @@ -2242,10 +2318,17 @@ descendant of the old head, you may force the update with: $ 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 --------------------------- @@ -2319,6 +2402,7 @@ Git internals Git depends on two fundamental abstractions: the "object database", and the "current directory cache" aka "index". +[[the-object-database]] The Object Database ------------------- @@ -2328,7 +2412,7 @@ 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. -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", @@ -2351,7 +2435,7 @@ the time of the commit). In addition, a "commit" refers to one or more 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 @@ -2388,6 +2472,7 @@ to just verifying their superficial consistency through the hash). The object types in some more detail: +[[blob-object]] Blob Object ----------- @@ -2409,6 +2494,7 @@ file is associated with in any way. 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 ----------- @@ -2450,6 +2536,7 @@ A tree is created with gitlink:git-write-tree[1] and 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 ------------- @@ -2467,7 +2554,7 @@ 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. -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 @@ -2476,6 +2563,7 @@ file manager. A commit is created with gitlink:git-commit-tree[1] and its data can be accessed by gitlink:git-cat-file[1]. +[[trust]] Trust ----- @@ -2505,6 +2593,7 @@ like GPG/PGP. To assist in this, git also provides the tag object... +[[tag-object]] Tag Object ---------- @@ -2527,11 +2616,12 @@ and the signature can be verified by 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 @@ -2581,6 +2671,7 @@ been written back to the backing store. +[[the-workflow]] The Workflow ------------ @@ -2590,6 +2681,7 @@ 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: +[[working-directory-to-index]] working directory -> index ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2623,6 +2715,7 @@ stat information. It will 'not' 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. +[[index-to-object-database]] index -> object database ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2638,6 +2731,7 @@ 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: +[[object-database-to-index]] object database -> index ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2654,6 +2748,7 @@ and your index file will now be equivalent to the tree that you saved earlier. However, that is only your 'index' file: your working directory contents have not been modified. +[[index-to-working-directory]] index -> working directory ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2683,6 +2778,7 @@ need to use the "-f" flag ('before' the "-a" flag or the filename) to 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 ~~~~~~~~~~~~~~~~~~~~~ @@ -2758,6 +2854,7 @@ various pieces fit together. ------------ +[[examining-the-data]] Examining the data ------------------ @@ -2793,6 +2890,7 @@ $ git-cat-file commit HEAD to see what the top commit was. +[[merging-multiple-trees]] Merging multiple trees ---------------------- @@ -2826,7 +2924,7 @@ since the tree object information is always the first line in a commit 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 @@ -2844,6 +2942,7 @@ index file, and you can just write the result out with `git-write-tree`. +[[merging-multiple-trees-2]] Merging multiple trees, continued --------------------------------- @@ -2879,14 +2978,14 @@ obviously the final outcome is what is in `HEAD`. What the 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 @@ -2914,6 +3013,7 @@ $ git-merge-index git-merge-one-file hello.c and that is what higher level `git merge -s resolve` is implemented with. +[[pack-files]] How git stores objects efficiently: pack files ---------------------------------------------- @@ -2984,11 +3084,10 @@ objects. They are not a problem. 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 <>. 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 @@ -3010,15 +3109,22 @@ 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). -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 --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 +------------------------------------------------ + +For blobs and trees, you can't do the same, but you can still examine +them. You can just do ------------------------------------------------ $ git show @@ -3055,8 +3161,10 @@ 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 *BAD* idea). +[[glossary]] include::glossary.txt[] +[[todo]] Notes and todo list for this manual =================================== -- 2.26.2