From b27a23e35d8e532e47661595bda642ef3a7375f1 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 24 May 2008 20:56:44 +0200 Subject: Documentation: convert tutorials to man pages This patch renames the following documents and at the same time converts them to the man page format: cvs-migration.txt -> gitcvs-migration.txt tutorial.txt -> gittutorial.txt tutorial-2.txt -> gittutorial-2.txt These new man pages are put in section 7, and other documents that reference the above ones are change accordingly. [jc: with help from Nanako to clean things up] Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/Makefile | 8 +- Documentation/core-tutorial.txt | 4 +- Documentation/cvs-migration.txt | 172 ----------- Documentation/git.txt | 4 +- Documentation/gitcvs-migration.txt | 193 ++++++++++++ Documentation/gittutorial-2.txt | 428 ++++++++++++++++++++++++++ Documentation/gittutorial.txt | 606 +++++++++++++++++++++++++++++++++++++ Documentation/tutorial-2.txt | 406 ------------------------- Documentation/tutorial.txt | 584 ----------------------------------- Documentation/user-manual.txt | 4 +- 10 files changed, 1236 insertions(+), 1173 deletions(-) delete mode 100644 Documentation/cvs-migration.txt create mode 100644 Documentation/gitcvs-migration.txt create mode 100644 Documentation/gittutorial-2.txt create mode 100644 Documentation/gittutorial.txt delete mode 100644 Documentation/tutorial-2.txt delete mode 100644 Documentation/tutorial.txt (limited to 'Documentation') diff --git a/Documentation/Makefile b/Documentation/Makefile index 4144d1e08..9750334b9 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -3,7 +3,8 @@ MAN1_TXT= \ $(wildcard git-*.txt)) \ gitk.txt MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt githooks.txt -MAN7_TXT=git.txt gitcli.txt +MAN7_TXT=git.txt gitcli.txt gittutorial.txt gittutorial-2.txt \ + gitcvs-migration.txt MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT) MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT)) @@ -11,10 +12,7 @@ MAN_HTML=$(patsubst %.txt,%.html,$(MAN_TXT)) DOC_HTML=$(MAN_HTML) -ARTICLES = tutorial -ARTICLES += tutorial-2 -ARTICLES += core-tutorial -ARTICLES += cvs-migration +ARTICLES = core-tutorial ARTICLES += diffcore ARTICLES += howto-index ARTICLES += repository-layout diff --git a/Documentation/core-tutorial.txt b/Documentation/core-tutorial.txt index 5a5531222..b50b5dd48 100644 --- a/Documentation/core-tutorial.txt +++ b/Documentation/core-tutorial.txt @@ -8,7 +8,7 @@ This tutorial explains how to use the "core" git programs to set up and work with a git repository. If you just need to use git as a revision control system you may prefer -to start with link:tutorial.html[a tutorial introduction to git] or +to start with linkgit:gittutorial[7][a tutorial introduction to git] or link:user-manual.html[the git user manual]. However, an understanding of these low-level tools can be helpful if @@ -1581,7 +1581,7 @@ suggested in the previous section may be new to you. You do not have to worry. git supports "shared public repository" style of cooperation you are probably more familiar with as well. -See link:cvs-migration.html[git for CVS users] for the details. +See linkgit:gitcvs-migration[7][git for CVS users] for the details. Bundling your work together --------------------------- diff --git a/Documentation/cvs-migration.txt b/Documentation/cvs-migration.txt deleted file mode 100644 index 374bc87b1..000000000 --- a/Documentation/cvs-migration.txt +++ /dev/null @@ -1,172 +0,0 @@ -git for CVS users -================= - -Git differs from CVS in that every working tree contains a repository with -a full copy of the project history, and no repository is inherently more -important than any other. However, you can emulate the CVS model by -designating a single shared repository which people can synchronize with; -this document explains how to do that. - -Some basic familiarity with git is required. This -link:tutorial.html[tutorial introduction to git] and the -link:glossary.html[git glossary] should be sufficient. - -Developing against a shared repository --------------------------------------- - -Suppose a shared repository is set up in /pub/repo.git on the host -foo.com. Then as an individual committer you can clone the shared -repository over ssh with: - ------------------------------------------------- -$ git clone foo.com:/pub/repo.git/ my-project -$ cd my-project ------------------------------------------------- - -and hack away. The equivalent of `cvs update` is - ------------------------------------------------- -$ git pull origin ------------------------------------------------- - -which merges in any work that others might have done since the clone -operation. If there are uncommitted changes in your working tree, commit -them first before running git pull. - -[NOTE] -================================ -The `pull` command knows where to get updates from because of certain -configuration variables that were set by the first `git clone` -command; see `git config -l` and the linkgit:git-config[1] man -page for details. -================================ - -You can update the shared repository with your changes by first committing -your changes, and then using the linkgit:git-push[1] command: - ------------------------------------------------- -$ git push origin master ------------------------------------------------- - -to "push" those commits to the shared repository. If someone else has -updated the repository more recently, `git push`, like `cvs commit`, will -complain, in which case you must pull any changes before attempting the -push again. - -In the `git push` command above we specify the name of the remote branch -to update (`master`). If we leave that out, `git push` tries to update -any branches in the remote repository that have the same name as a branch -in the local repository. So the last `push` can be done with either of: - ------------- -$ git push origin -$ git push foo.com:/pub/project.git/ ------------- - -as long as the shared repository does not have any branches -other than `master`. - -Setting Up a Shared Repository ------------------------------- - -We assume you have already created a git repository for your project, -possibly created from scratch or from a tarball (see the -link:tutorial.html[tutorial]), or imported from an already existing CVS -repository (see the next section). - -Assume your existing repo is at /home/alice/myproject. Create a new "bare" -repository (a repository without a working tree) and fetch your project into -it: - ------------------------------------------------- -$ mkdir /pub/my-repo.git -$ cd /pub/my-repo.git -$ git --bare init --shared -$ git --bare fetch /home/alice/myproject master:master ------------------------------------------------- - -Next, give every team member read/write access to this repository. One -easy way to do this is to give all the team members ssh access to the -machine where the repository is hosted. If you don't want to give them a -full shell on the machine, there is a restricted shell which only allows -users to do git pushes and pulls; see linkgit:git-shell[1]. - -Put all the committers in the same group, and make the repository -writable by that group: - ------------------------------------------------- -$ chgrp -R $group /pub/my-repo.git ------------------------------------------------- - -Make sure committers have a umask of at most 027, so that the directories -they create are writable and searchable by other group members. - -Importing a CVS archive ------------------------ - -First, install version 2.1 or higher of cvsps from -link:http://www.cobite.com/cvsps/[http://www.cobite.com/cvsps/] and make -sure it is in your path. Then cd to a checked out CVS working directory -of the project you are interested in and run linkgit:git-cvsimport[1]: - -------------------------------------------- -$ git cvsimport -C -------------------------------------------- - -This puts a git archive of the named CVS module in the directory -, which will be created if necessary. - -The import checks out from CVS every revision of every file. Reportedly -cvsimport can average some twenty revisions per second, so for a -medium-sized project this should not take more than a couple of minutes. -Larger projects or remote repositories may take longer. - -The main trunk is stored in the git branch named `origin`, and additional -CVS branches are stored in git branches with the same names. The most -recent version of the main trunk is also left checked out on the `master` -branch, so you can start adding your own changes right away. - -The import is incremental, so if you call it again next month it will -fetch any CVS updates that have been made in the meantime. For this to -work, you must not modify the imported branches; instead, create new -branches for your own changes, and merge in the imported branches as -necessary. - -Advanced Shared Repository Management -------------------------------------- - -Git allows you to specify scripts called "hooks" to be run at certain -points. You can use these, for example, to send all commits to the shared -repository to a mailing list. See linkgit:githooks[5][Hooks used by git]. - -You can enforce finer grained permissions using update hooks. See -link:howto/update-hook-example.txt[Controlling access to branches using -update hooks]. - -Providing CVS Access to a git Repository ----------------------------------------- - -It is also possible to provide true CVS access to a git repository, so -that developers can still use CVS; see linkgit:git-cvsserver[1] for -details. - -Alternative Development Models ------------------------------- - -CVS users are accustomed to giving a group of developers commit access to -a common repository. As we've seen, this is also possible with git. -However, the distributed nature of git allows other development models, -and you may want to first consider whether one of them might be a better -fit for your project. - -For example, you can choose a single person to maintain the project's -primary public repository. Other developers then clone this repository -and each work in their own clone. When they have a series of changes that -they're happy with, they ask the maintainer to pull from the branch -containing the changes. The maintainer reviews their changes and pulls -them into the primary repository, which other developers pull from as -necessary to stay coordinated. The Linux kernel and other projects use -variants of this model. - -With a small group, developers may just pull changes from each other's -repositories without the need for a central maintainer. diff --git a/Documentation/git.txt b/Documentation/git.txt index adcd3e00b..735f0d19c 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -20,10 +20,10 @@ Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals. -See this link:tutorial.html[tutorial] to get started, then see +See this linkgit:gittutorial[7][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]. See +also want to read linkgit:gitcvs-migration[7][CVS migration]. See link:user-manual.html[Git User's Manual] for a more in-depth introduction. diff --git a/Documentation/gitcvs-migration.txt b/Documentation/gitcvs-migration.txt new file mode 100644 index 000000000..c41080502 --- /dev/null +++ b/Documentation/gitcvs-migration.txt @@ -0,0 +1,193 @@ +gitcvs-migration(7) +=================== + +NAME +---- +gitcvs-migration - git for CVS users + +SYNOPSIS +-------- +git cvsimport * + +DESCRIPTION +----------- + +Git differs from CVS in that every working tree contains a repository with +a full copy of the project history, and no repository is inherently more +important than any other. However, you can emulate the CVS model by +designating a single shared repository which people can synchronize with; +this document explains how to do that. + +Some basic familiarity with git is required. This +linkgit:gittutorial[7][tutorial introduction to git] and the +link:glossary.html[git glossary] should be sufficient. + +Developing against a shared repository +-------------------------------------- + +Suppose a shared repository is set up in /pub/repo.git on the host +foo.com. Then as an individual committer you can clone the shared +repository over ssh with: + +------------------------------------------------ +$ git clone foo.com:/pub/repo.git/ my-project +$ cd my-project +------------------------------------------------ + +and hack away. The equivalent of `cvs update` is + +------------------------------------------------ +$ git pull origin +------------------------------------------------ + +which merges in any work that others might have done since the clone +operation. If there are uncommitted changes in your working tree, commit +them first before running git pull. + +[NOTE] +================================ +The `pull` command knows where to get updates from because of certain +configuration variables that were set by the first `git clone` +command; see `git config -l` and the linkgit:git-config[1] man +page for details. +================================ + +You can update the shared repository with your changes by first committing +your changes, and then using the linkgit:git-push[1] command: + +------------------------------------------------ +$ git push origin master +------------------------------------------------ + +to "push" those commits to the shared repository. If someone else has +updated the repository more recently, `git push`, like `cvs commit`, will +complain, in which case you must pull any changes before attempting the +push again. + +In the `git push` command above we specify the name of the remote branch +to update (`master`). If we leave that out, `git push` tries to update +any branches in the remote repository that have the same name as a branch +in the local repository. So the last `push` can be done with either of: + +------------ +$ git push origin +$ git push foo.com:/pub/project.git/ +------------ + +as long as the shared repository does not have any branches +other than `master`. + +Setting Up a Shared Repository +------------------------------ + +We assume you have already created a git repository for your project, +possibly created from scratch or from a tarball (see the +linkgit:gittutorial[7][tutorial]), or imported from an already existing CVS +repository (see the next section). + +Assume your existing repo is at /home/alice/myproject. Create a new "bare" +repository (a repository without a working tree) and fetch your project into +it: + +------------------------------------------------ +$ mkdir /pub/my-repo.git +$ cd /pub/my-repo.git +$ git --bare init --shared +$ git --bare fetch /home/alice/myproject master:master +------------------------------------------------ + +Next, give every team member read/write access to this repository. One +easy way to do this is to give all the team members ssh access to the +machine where the repository is hosted. If you don't want to give them a +full shell on the machine, there is a restricted shell which only allows +users to do git pushes and pulls; see linkgit:git-shell[1]. + +Put all the committers in the same group, and make the repository +writable by that group: + +------------------------------------------------ +$ chgrp -R $group /pub/my-repo.git +------------------------------------------------ + +Make sure committers have a umask of at most 027, so that the directories +they create are writable and searchable by other group members. + +Importing a CVS archive +----------------------- + +First, install version 2.1 or higher of cvsps from +link:http://www.cobite.com/cvsps/[http://www.cobite.com/cvsps/] and make +sure it is in your path. Then cd to a checked out CVS working directory +of the project you are interested in and run linkgit:git-cvsimport[1]: + +------------------------------------------- +$ git cvsimport -C +------------------------------------------- + +This puts a git archive of the named CVS module in the directory +, which will be created if necessary. + +The import checks out from CVS every revision of every file. Reportedly +cvsimport can average some twenty revisions per second, so for a +medium-sized project this should not take more than a couple of minutes. +Larger projects or remote repositories may take longer. + +The main trunk is stored in the git branch named `origin`, and additional +CVS branches are stored in git branches with the same names. The most +recent version of the main trunk is also left checked out on the `master` +branch, so you can start adding your own changes right away. + +The import is incremental, so if you call it again next month it will +fetch any CVS updates that have been made in the meantime. For this to +work, you must not modify the imported branches; instead, create new +branches for your own changes, and merge in the imported branches as +necessary. + +Advanced Shared Repository Management +------------------------------------- + +Git allows you to specify scripts called "hooks" to be run at certain +points. You can use these, for example, to send all commits to the shared +repository to a mailing list. See linkgit:githooks[5][Hooks used by git]. + +You can enforce finer grained permissions using update hooks. See +link:howto/update-hook-example.txt[Controlling access to branches using +update hooks]. + +Providing CVS Access to a git Repository +---------------------------------------- + +It is also possible to provide true CVS access to a git repository, so +that developers can still use CVS; see linkgit:git-cvsserver[1] for +details. + +Alternative Development Models +------------------------------ + +CVS users are accustomed to giving a group of developers commit access to +a common repository. As we've seen, this is also possible with git. +However, the distributed nature of git allows other development models, +and you may want to first consider whether one of them might be a better +fit for your project. + +For example, you can choose a single person to maintain the project's +primary public repository. Other developers then clone this repository +and each work in their own clone. When they have a series of changes that +they're happy with, they ask the maintainer to pull from the branch +containing the changes. The maintainer reviews their changes and pulls +them into the primary repository, which other developers pull from as +necessary to stay coordinated. The Linux kernel and other projects use +variants of this model. + +With a small group, developers may just pull changes from each other's +repositories without the need for a central maintainer. + +SEE ALSO +-------- +linkgit:gittutorial[7], linkgit:gittutorial-2[7], +link:everyday.html[Everyday Git], +link:user-manual.html[The Git User's Manual] + +GIT +--- +Part of the linkgit:git[7] suite. diff --git a/Documentation/gittutorial-2.txt b/Documentation/gittutorial-2.txt new file mode 100644 index 000000000..5bbbf4305 --- /dev/null +++ b/Documentation/gittutorial-2.txt @@ -0,0 +1,428 @@ +gittutorial-2(7) +================ + +NAME +---- +gittutorial-2 - A tutorial introduction to git: part two + +SYNOPSIS +-------- +git * + +DESCRIPTION +----------- + +You should work through linkgit:gittutorial[7][A tutorial introduction to +git] before reading this tutorial. + +The goal of this tutorial is to introduce two fundamental pieces of +git's architecture--the object database and the index file--and to +provide the reader with everything necessary to understand the rest +of the git documentation. + +The git object database +----------------------- + +Let's start a new project and create a small amount of history: + +------------------------------------------------ +$ mkdir test-project +$ cd test-project +$ git init +Initialized empty Git repository in .git/ +$ echo 'hello world' > file.txt +$ git add . +$ git commit -a -m "initial commit" +Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7 + create mode 100644 file.txt +$ echo 'hello world!' >file.txt +$ git commit -a -m "add emphasis" +Created commit c4d59f390b9cfd4318117afde11d601c1085f241 +------------------------------------------------ + +What are the 40 digits of hex that git responded to the commit with? + +We saw in part one of the tutorial that commits have names like this. +It turns out that every object in the git history is stored under +such a 40-digit hex name. That name is the SHA1 hash of the object's +contents; among other things, this ensures that git will never store +the same data twice (since identical data is given an identical SHA1 +name), and that the contents of a git object will never change (since +that would change the object's name as well). + +It is expected that the content of the commit object you created while +following the example above generates a different SHA1 hash than +the one shown above because the commit object records the time when +it was created and the name of the person performing the commit. + +We can ask git about this particular object with the cat-file +command. Don't copy the 40 hex digits from this example but use those +from your own version. Note that you can shorten it to only a few +characters to save yourself typing all 40 hex digits: + +------------------------------------------------ +$ git-cat-file -t 54196cc2 +commit +$ git-cat-file commit 54196cc2 +tree 92b8b694ffb1675e5975148e1121810081dbdffe +author J. Bruce Fields 1143414668 -0500 +committer J. Bruce Fields 1143414668 -0500 + +initial commit +------------------------------------------------ + +A tree can refer to one or more "blob" objects, each corresponding to +a file. In addition, a tree can also refer to other tree objects, +thus creating a directory hierarchy. You can examine the contents of +any tree using ls-tree (remember that a long enough initial portion +of the SHA1 will also work): + +------------------------------------------------ +$ git ls-tree 92b8b694 +100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad file.txt +------------------------------------------------ + +Thus we see that this tree has one file in it. The SHA1 hash is a +reference to that file's data: + +------------------------------------------------ +$ git cat-file -t 3b18e512 +blob +------------------------------------------------ + +A "blob" is just file data, which we can also examine with cat-file: + +------------------------------------------------ +$ git cat-file blob 3b18e512 +hello world +------------------------------------------------ + +Note that this is the old file data; so the object that git named in +its response to the initial tree was a tree with a snapshot of the +directory state that was recorded by the first commit. + +All of these objects are stored under their SHA1 names inside the git +directory: + +------------------------------------------------ +$ find .git/objects/ +.git/objects/ +.git/objects/pack +.git/objects/info +.git/objects/3b +.git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad +.git/objects/92 +.git/objects/92/b8b694ffb1675e5975148e1121810081dbdffe +.git/objects/54 +.git/objects/54/196cc2703dc165cbd373a65a4dcf22d50ae7f7 +.git/objects/a0 +.git/objects/a0/423896973644771497bdc03eb99d5281615b51 +.git/objects/d0 +.git/objects/d0/492b368b66bdabf2ac1fd8c92b39d3db916e59 +.git/objects/c4 +.git/objects/c4/d59f390b9cfd4318117afde11d601c1085f241 +------------------------------------------------ + +and the contents of these files is just the compressed data plus a +header identifying their length and their type. The type is either a +blob, a tree, a commit, or a tag. + +The simplest commit to find is the HEAD commit, which we can find +from .git/HEAD: + +------------------------------------------------ +$ cat .git/HEAD +ref: refs/heads/master +------------------------------------------------ + +As you can see, this tells us which branch we're currently on, and it +tells us this by naming a file under the .git directory, which itself +contains a SHA1 name referring to a commit object, which we can +examine with cat-file: + +------------------------------------------------ +$ cat .git/refs/heads/master +c4d59f390b9cfd4318117afde11d601c1085f241 +$ git cat-file -t c4d59f39 +commit +$ git cat-file commit c4d59f39 +tree d0492b368b66bdabf2ac1fd8c92b39d3db916e59 +parent 54196cc2703dc165cbd373a65a4dcf22d50ae7f7 +author J. Bruce Fields 1143418702 -0500 +committer J. Bruce Fields 1143418702 -0500 + +add emphasis +------------------------------------------------ + +The "tree" object here refers to the new state of the tree: + +------------------------------------------------ +$ git ls-tree d0492b36 +100644 blob a0423896973644771497bdc03eb99d5281615b51 file.txt +$ git cat-file blob a0423896 +hello world! +------------------------------------------------ + +and the "parent" object refers to the previous commit: + +------------------------------------------------ +$ git-cat-file commit 54196cc2 +tree 92b8b694ffb1675e5975148e1121810081dbdffe +author J. Bruce Fields 1143414668 -0500 +committer J. Bruce Fields 1143414668 -0500 + +initial commit +------------------------------------------------ + +The tree object is the tree we examined first, and this commit is +unusual in that it lacks any parent. + +Most commits have only one parent, but it is also common for a commit +to have multiple parents. In that case the commit represents a +merge, with the parent references pointing to the heads of the merged +branches. + +Besides blobs, trees, and commits, the only remaining type of object +is a "tag", which we won't discuss here; refer to linkgit:git-tag[1] +for details. + +So now we know how git uses the object database to represent a +project's history: + + * "commit" objects refer to "tree" objects representing the + snapshot of a directory tree at a particular point in the + history, and refer to "parent" commits to show how they're + connected into the project history. + * "tree" objects represent the state of a single directory, + associating directory names to "blob" objects containing file + data and "tree" objects containing subdirectory information. + * "blob" objects contain file data without any other structure. + * References to commit objects at the head of each branch are + stored in files under .git/refs/heads/. + * The name of the current branch is stored in .git/HEAD. + +Note, by the way, that lots of commands take a tree as an argument. +But as we can see above, a tree can be referred to in many different +ways--by the SHA1 name for that tree, by the name of a commit that +refers to the tree, by the name of a branch whose head refers to that +tree, etc.--and most such commands can accept any of these names. + +In command synopses, the word "tree-ish" is sometimes used to +designate such an argument. + +The index file +-------------- + +The primary tool we've been using to create commits is "git commit +-a", which creates a commit including every change you've made to +your working tree. But what if you want to commit changes only to +certain files? Or only certain changes to certain files? + +If we look at the way commits are created under the cover, we'll see +that there are more flexible ways creating commits. + +Continuing with our test-project, let's modify file.txt again: + +------------------------------------------------ +$ echo "hello world, again" >>file.txt +------------------------------------------------ + +but this time instead of immediately making the commit, let's take an +intermediate step, and ask for diffs along the way to keep track of +what's happening: + +------------------------------------------------ +$ git diff +--- a/file.txt ++++ b/file.txt +@@ -1 +1,2 @@ + hello world! ++hello world, again +$ git add file.txt +$ git diff +------------------------------------------------ + +The last diff is empty, but no new commits have been made, and the +head still doesn't contain the new line: + +------------------------------------------------ +$ git-diff HEAD +diff --git a/file.txt b/file.txt +index a042389..513feba 100644 +--- a/file.txt ++++ b/file.txt +@@ -1 +1,2 @@ + hello world! ++hello world, again +------------------------------------------------ + +So "git diff" is comparing against something other than the head. +The thing that it's comparing against is actually the index file, +which is stored in .git/index in a binary format, but whose contents +we can examine with ls-files: + +------------------------------------------------ +$ git ls-files --stage +100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt +$ git cat-file -t 513feba2 +blob +$ git cat-file blob 513feba2 +hello world! +hello world, again +------------------------------------------------ + +So what our "git add" did was store a new blob and then put +a reference to it in the index file. If we modify the file again, +we'll see that the new modifications are reflected in the "git-diff" +output: + +------------------------------------------------ +$ echo 'again?' >>file.txt +$ git diff +index 513feba..ba3da7b 100644 +--- a/file.txt ++++ b/file.txt +@@ -1,2 +1,3 @@ + hello world! + hello world, again ++again? +------------------------------------------------ + +With the right arguments, git diff can also show us the difference +between the working directory and the last commit, or between the +index and the last commit: + +------------------------------------------------ +$ git diff HEAD +diff --git a/file.txt b/file.txt +index a042389..ba3da7b 100644 +--- a/file.txt ++++ b/file.txt +@@ -1 +1,3 @@ + hello world! ++hello world, again ++again? +$ git diff --cached +diff --git a/file.txt b/file.txt +index a042389..513feba 100644 +--- a/file.txt ++++ b/file.txt +@@ -1 +1,2 @@ + hello world! ++hello world, again +------------------------------------------------ + +At any time, we can create a new commit using "git commit" (without +the -a option), and verify that the state committed only includes the +changes stored in the index file, not the additional change that is +still only in our working tree: + +------------------------------------------------ +$ git commit -m "repeat" +$ git diff HEAD +diff --git a/file.txt b/file.txt +index 513feba..ba3da7b 100644 +--- a/file.txt ++++ b/file.txt +@@ -1,2 +1,3 @@ + hello world! + hello world, again ++again? +------------------------------------------------ + +So by default "git commit" uses the index to create the commit, not +the working tree; the -a option to commit tells it to first update +the index with all changes in the working tree. + +Finally, it's worth looking at the effect of "git add" on the index +file: + +------------------------------------------------ +$ echo "goodbye, world" >closing.txt +$ git add closing.txt +------------------------------------------------ + +The effect of the "git add" was to add one entry to the index file: + +------------------------------------------------ +$ git ls-files --stage +100644 8b9743b20d4b15be3955fc8d5cd2b09cd2336138 0 closing.txt +100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt +------------------------------------------------ + +And, as you can see with cat-file, this new entry refers to the +current contents of the file: + +------------------------------------------------ +$ git cat-file blob 8b9743b2 +goodbye, world +------------------------------------------------ + +The "status" command is a useful way to get a quick summary of the +situation: + +------------------------------------------------ +$ git status +# On branch master +# Changes to be committed: +# (use "git reset HEAD ..." to unstage) +# +# new file: closing.txt +# +# Changed but not updated: +# (use "git add ..." to update what will be committed) +# +# modified: file.txt +# +------------------------------------------------ + +Since the current state of closing.txt is cached in the index file, +it is listed as "Changes to be committed". Since file.txt has +changes in the working directory that aren't reflected in the index, +it is marked "changed but not updated". At this point, running "git +commit" would create a commit that added closing.txt (with its new +contents), but that didn't modify file.txt. + +Also, note that a bare "git diff" shows the changes to file.txt, but +not the addition of closing.txt, because the version of closing.txt +in the index file is identical to the one in the working directory. + +In addition to being the staging area for new commits, the index file +is also populated from the object database when checking out a +branch, and is used to hold the trees involved in a merge operation. +See the link:core-tutorial.html[core tutorial] and the relevant man +pages for details. + +What next? +---------- + +At this point you should know everything necessary to read the man +pages for any of the git commands; one good place to start would be +with the commands mentioned in link:everyday.html[Everyday git]. You +should be able to find any unknown jargon in the +link:glossary.html[Glossary]. + +The link:user-manual.html[Git User's Manual] provides a more +comprehensive introduction to git. + +The linkgit:gitcvs-migration[7][CVS migration] document explains how to +import a CVS repository into git, and shows how to use git in a +CVS-like way. + +For some interesting examples of git use, see the +link:howto-index.html[howtos]. + +For git developers, the link:core-tutorial.html[Core tutorial] goes +into detail on the lower-level git mechanisms involved in, for +example, creating a new commit. + +SEE ALSO +-------- +linkgit:gittutorial[7], +linkgit:gitcvs-migration[7], +link:everyday.html[Everyday git], +link:user-manual.html[The Git User's Manual] + +GIT +--- +Part of the linkgit:git[7] suite. diff --git a/Documentation/gittutorial.txt b/Documentation/gittutorial.txt new file mode 100644 index 000000000..898acdb53 --- /dev/null +++ b/Documentation/gittutorial.txt @@ -0,0 +1,606 @@ +gittutorial(7) +============== + +NAME +---- +gittutorial - A tutorial introduction to git (for version 1.5.1 or newer) + +SYNOPSIS +-------- +git * + +DESCRIPTION +----------- + +This tutorial explains how to import a new project into git, make +changes to it, and share changes with other developers. + +If you are instead primarily interested in using git to fetch a project, +for example, to test the latest version, you may prefer to start with +the first two chapters of link:user-manual.html[The Git User's Manual]. + +First, note that you can get documentation for a command such as "git +diff" with: + +------------------------------------------------ +$ man git-diff +------------------------------------------------ + +It is a good idea to introduce yourself to git with your name and +public email address before doing any operation. The easiest +way to do so is: + +------------------------------------------------ +$ git config --global user.name "Your Name Comes Here" +$ git config --global user.email you@yourdomain.example.com +------------------------------------------------ + + +Importing a new project +----------------------- + +Assume you have a tarball project.tar.gz with your initial work. You +can place it under git revision control as follows. + +------------------------------------------------ +$ tar xzf project.tar.gz +$ cd project +$ git init +------------------------------------------------ + +Git will reply + +------------------------------------------------ +Initialized empty Git repository in .git/ +------------------------------------------------ + +You've now initialized the working directory--you may notice a new +directory created, named ".git". + +Next, tell git to take a snapshot of the contents of all files under the +current directory (note the '.'), with linkgit:git-add[1]: + +------------------------------------------------ +$ git add . +------------------------------------------------ + +This snapshot is now stored in a temporary staging area which git calls +the "index". You can permanently store the contents of the index in the +repository with linkgit:git-commit[1]: + +------------------------------------------------ +$ git commit +------------------------------------------------ + +This will prompt you for a commit message. You've now stored the first +version of your project in git. + +Making changes +-------------- + +Modify some files, then add their updated contents to the index: + +------------------------------------------------ +$ git add file1 file2 file3 +------------------------------------------------ + +You are now ready to commit. You can see what is about to be committed +using linkgit:git-diff[1] with the --cached option: + +------------------------------------------------ +$ git diff --cached +------------------------------------------------ + +(Without --cached, linkgit:git-diff[1] will show you any changes that +you've made but not yet added to the index.) You can also get a brief +summary of the situation with linkgit:git-status[1]: + +------------------------------------------------ +$ git status +# On branch master +# Changes to be committed: +# (use "git reset HEAD ..." to unstage) +# +# modified: file1 +# modified: file2 +# modified: file3 +# +------------------------------------------------ + +If you need to make any further adjustments, do so now, and then add any +newly modified content to the index. Finally, commit your changes with: + +------------------------------------------------ +$ git commit +------------------------------------------------ + +This will again prompt your for a message describing the change, and then +record a new version of the project. + +Alternatively, instead of running `git add` beforehand, you can use + +------------------------------------------------ +$ git commit -a +------------------------------------------------ + +which will automatically notice any modified (but not new) files, add +them to the index, and commit, all in one step. + +A note on 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. + +Git tracks content not files +---------------------------- + +Many revision control systems provide an "add" command that tells the +system to start tracking changes to a new file. Git's "add" command +does something simpler and more powerful: `git add` is used both for new +and newly modified files, and in both cases it takes a snapshot of the +given files and stages that content in the index, ready for inclusion in +the next commit. + +Viewing project history +----------------------- + +At any point you can view the history of your changes using + +------------------------------------------------ +$ git log +------------------------------------------------ + +If you also want to see complete diffs at each step, use + +------------------------------------------------ +$ git log -p +------------------------------------------------ + +Often the overview of the change is useful to get a feel of +each step + +------------------------------------------------ +$ git log --stat --summary +------------------------------------------------ + +Managing branches +----------------- + +A single git repository can maintain multiple branches of +development. To create a new branch named "experimental", use + +------------------------------------------------ +$ git branch experimental +------------------------------------------------ + +If you now run + +------------------------------------------------ +$ git branch +------------------------------------------------ + +you'll get a list of all existing branches: + +------------------------------------------------ + experimental +* master +------------------------------------------------ + +The "experimental" branch is the one you just created, and the +"master" branch is a default branch that was created for you +automatically. The asterisk marks the branch you are currently on; +type + +------------------------------------------------ +$ git checkout experimental +------------------------------------------------ + +to switch to the experimental branch. Now edit a file, commit the +change, and switch back to the master branch: + +------------------------------------------------ +(edit file) +$ git commit -a +$ git checkout master +------------------------------------------------ + +Check that the change you made is no longer visible, since it was +made on the experimental branch and you're back on the master branch. + +You can make a different change on the master branch: + +------------------------------------------------ +(edit file) +$ git commit -a +------------------------------------------------ + +at this point the two branches have diverged, with different changes +made in each. To merge the changes made in experimental into master, run + +------------------------------------------------ +$ git merge experimental +------------------------------------------------ + +If the changes don't conflict, you're done. If there are conflicts, +markers will be left in the problematic files showing the conflict; + +------------------------------------------------ +$ git diff +------------------------------------------------ + +will show this. Once you've edited the files to resolve the +conflicts, + +------------------------------------------------ +$ git commit -a +------------------------------------------------ + +will commit the result of the merge. Finally, + +------------------------------------------------ +$ gitk +------------------------------------------------ + +will show a nice graphical representation of the resulting history. + +At this point you could delete the experimental branch with + +------------------------------------------------ +$ git branch -d experimental +------------------------------------------------ + +This command ensures that the changes in the experimental branch are +already in the current branch. + +If you develop on a branch crazy-idea, then regret it, you can always +delete the branch with + +------------------------------------- +$ git branch -D crazy-idea +------------------------------------- + +Branches are cheap and easy, so this is a good way to try something +out. + +Using git for collaboration +--------------------------- + +Suppose that Alice has started a new project with a git repository in +/home/alice/project, and that Bob, who has a home directory on the +same machine, wants to contribute. + +Bob begins with: + +------------------------------------------------ +$ git clone /home/alice/project myrepo +------------------------------------------------ + +This creates a new directory "myrepo" containing a clone of Alice's +repository. The clone is on an equal footing with the original +project, possessing its own copy of the original project's history. + +Bob then makes some changes and commits them: + +------------------------------------------------ +(edit files) +$ git commit -a +(repeat as necessary) +------------------------------------------------ + +When he's ready, he tells Alice to pull changes from the repository +at /home/bob/myrepo. She does this with: + +------------------------------------------------ +$ cd /home/alice/project +$ git pull /home/bob/myrepo master +------------------------------------------------ + +This merges the changes from Bob's "master" branch into Alice's +current branch. If Alice has made her own changes in the meantime, +then she may need to manually fix any conflicts. (Note that the +"master" argument in the above command is actually unnecessary, as it +is the default.) + +The "pull" command thus performs two operations: it fetches changes +from a remote branch, then merges them into the current branch. + +When you are working in a small closely knit group, it is not +unusual to interact with the same repository over and over +again. By defining 'remote' repository shorthand, you can make +it easier: + +------------------------------------------------ +$ git remote add bob /home/bob/myrepo +------------------------------------------------ + +With this, Alice can perform the first operation alone using the +"git fetch" command without merging them with her own branch, +using: + +------------------------------------- +$ git fetch bob +------------------------------------- + +Unlike the longhand form, when Alice fetches from Bob using a +remote repository shorthand set up with `git remote`, what was +fetched is stored in a remote tracking branch, in this case +`bob/master`. So after this: + +------------------------------------- +$ git log -p master..bob/master +------------------------------------- + +shows a list of all the changes that Bob made since he branched from +Alice's master branch. + +After examining those changes, Alice +could merge the changes into her master branch: + +------------------------------------- +$ git merge bob/master +------------------------------------- + +This `merge` can also be done by 'pulling from her own remote +tracking branch', like this: + +------------------------------------- +$ git pull . remotes/bob/master +------------------------------------- + +Note that git pull always merges into the current branch, +regardless of what else is given on the command line. + +Later, Bob can update his repo with Alice's latest changes using + +------------------------------------- +$ git pull +------------------------------------- + +Note that he doesn't need to give the path to Alice's repository; +when Bob cloned Alice's repository, git stored the location of her +repository in the repository configuration, and that location is +used for pulls: + +------------------------------------- +$ git config --get remote.origin.url +/home/alice/project +------------------------------------- + +(The complete configuration created by git-clone is visible using +"git config -l", and the linkgit:git-config[1] man page +explains the meaning of each option.) + +Git also keeps a pristine copy of Alice's master branch under the +name "origin/master": + +------------------------------------- +$ git branch -r + origin/master +------------------------------------- + +If Bob later decides to work from a different host, he can still +perform clones and pulls using the ssh protocol: + +------------------------------------- +$ git clone alice.org:/home/alice/project myrepo +------------------------------------- + +Alternatively, git has a native protocol, or can use rsync or http; +see linkgit:git-pull[1] for details. + +Git can also be used in a CVS-like mode, with a central repository +that various users push changes to; see linkgit:git-push[1] and +linkgit:gitcvs-migration[7][git for CVS users]. + +Exploring history +----------------- + +Git history is represented as a series of interrelated commits. We +have already seen that the git log command can list those commits. +Note that first line of each git log entry also gives a name for the +commit: + +------------------------------------- +$ git log +commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 +Author: Junio C Hamano +Date: Tue May 16 17:18:22 2006 -0700 + + merge-base: Clarify the comments on post processing. +------------------------------------- + +We can give this name to git show to see the details about this +commit. + +------------------------------------- +$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 +------------------------------------- + +But there are other ways to refer to commits. You can use any initial +part of the name that is long enough to uniquely identify the commit: + +------------------------------------- +$ git show c82a22c39c # the first few characters of the name are + # usually enough +$ git show HEAD # the tip of the current branch +$ git show experimental # the tip of the "experimental" branch +------------------------------------- + +Every commit usually has one "parent" commit +which points to the previous state of the project: + +------------------------------------- +$ git show HEAD^ # to see the parent of HEAD +$ git show HEAD^^ # to see the grandparent of HEAD +$ git show HEAD~4 # to see the great-great grandparent of HEAD +------------------------------------- + +Note that merge commits may have more than one parent: + +------------------------------------- +$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^) +$ git show HEAD^2 # show the second parent of HEAD +------------------------------------- + +You can also give commits names of your own; after running + +------------------------------------- +$ git-tag v2.5 1b2e1d63ff +------------------------------------- + +you can refer to 1b2e1d63ff by the name "v2.5". If you intend to +share this name with other people (for example, to identify a release +version), you should create a "tag" object, and perhaps sign it; see +linkgit:git-tag[1] for details. + +Any git command that needs to know a commit can take any of these +names. For example: + +------------------------------------- +$ git diff v2.5 HEAD # compare the current HEAD to v2.5 +$ git branch stable v2.5 # start a new branch named "stable" based + # at v2.5 +$ git reset --hard HEAD^ # reset your current branch and working + # directory to its state at HEAD^ +------------------------------------- + +Be careful with that last command: in addition to losing any changes +in the working directory, it will also remove all later commits from +this branch. If this branch is the only branch containing those +commits, they will be lost. Also, don't use "git reset" on a +publicly-visible branch that other developers pull from, as it will +force needless merges on other developers to clean up the history. +If you need to undo changes that you have pushed, use linkgit:git-revert[1] +instead. + +The git grep command can search for strings in any version of your +project, so + +------------------------------------- +$ git grep "hello" v2.5 +------------------------------------- + +searches for all occurrences of "hello" in v2.5. + +If you leave out the commit name, git grep will search any of the +files it manages in your current directory. So + +------------------------------------- +$ git grep "hello" +------------------------------------- + +is a quick way to search just the files that are tracked by git. + +Many git commands also take sets of commits, which can be specified +in a number of ways. Here are some examples with git log: + +------------------------------------- +$ git log v2.5..v2.6 # commits between v2.5 and v2.6 +$ git log v2.5.. # commits since v2.5 +$ git log --since="2 weeks ago" # commits from the last 2 weeks +$ git log v2.5.. Makefile # commits since v2.5 which modify + # Makefile +------------------------------------- + +You can also give git log a "range" of commits where the first is not +necessarily an ancestor of the second; for example, if the tips of +the branches "stable-release" and "master" diverged from a common +commit some time ago, then + +------------------------------------- +$ git log stable..experimental +------------------------------------- + +will list commits made in the experimental branch but not in the +stable branch, while + +------------------------------------- +$ git log experimental..stable +------------------------------------- + +will show the list of commits made on the stable branch but not +the experimental branch. + +The "git log" command has a weakness: it must present commits in a +list. When the history has lines of development that diverged and +then merged back together, the order in which "git log" presents +those commits is meaningless. + +Most projects with multiple contributors (such as the linux kernel, +or git itself) have frequent merges, and gitk does a better job of +visualizing their history. For example, + +------------------------------------- +$ gitk --since="2 weeks ago" drivers/ +------------------------------------- + +allows you to browse any commits from the last 2 weeks of commits +that modified files under the "drivers" directory. (Note: you can +adjust gitk's fonts by holding down the control key while pressing +"-" or "+".) + +Finally, most commands that take filenames will optionally allow you +to precede any filename by a commit, to specify a particular version +of the file: + +------------------------------------- +$ git diff v2.5:Makefile HEAD:Makefile.in +------------------------------------- + +You can also use "git show" to see any such file: + +------------------------------------- +$ git show v2.5:Makefile +------------------------------------- + +Next Steps +---------- + +This tutorial should be enough to perform basic distributed revision +control for your projects. However, to fully understand the depth +and power of git you need to understand two simple ideas on which it +is based: + + * The object database is the rather elegant system used to + store the history of your project--files, directories, and + commits. + + * The index file is a cache of the state of a directory tree, + used to create commits, check out working directories, and + hold the various trees involved in a merge. + +linkgit:gittutorial-2[7][Part two of this tutorial] explains the object +database, the index file, and a few other odds and ends that you'll +need to make the most of git. + +If you don't want to continue with that right away, a few other +digressions that may be interesting at this point are: + + * linkgit:git-format-patch[1], linkgit:git-am[1]: These convert + series of git commits into emailed patches, and vice versa, + useful for projects such as the linux kernel which rely heavily + on emailed patches. + + * linkgit:git-bisect[1]: When there is a regression in your + project, one way to track down the bug is by searching through + the history to find the exact commit that's to blame. Git bisect + can help you perform a binary search for that commit. It is + smart enough to perform a close-to-optimal search even in the + case of complex non-linear history with lots of merged branches. + + * link:everyday.html[Everyday GIT with 20 Commands Or So] + + * linkgit:gitcvs-migration[7][git for CVS users]. + +SEE ALSO +-------- +linkgit:gittutorial-2[7], +linkgit:gitcvs-migration[7], +link:everyday.html[Everyday git], +link:user-manual.html[The Git User's Manual] + +GIT +--- +Part of the linkgit:git[7] suite. diff --git a/Documentation/tutorial-2.txt b/Documentation/tutorial-2.txt deleted file mode 100644 index 7fac47de8..000000000 --- a/Documentation/tutorial-2.txt +++ /dev/null @@ -1,406 +0,0 @@ -A tutorial introduction to git: part two -======================================== - -You should work through link:tutorial.html[A tutorial introduction to -git] before reading this tutorial. - -The goal of this tutorial is to introduce two fundamental pieces of -git's architecture--the object database and the index file--and to -provide the reader with everything necessary to understand the rest -of the git documentation. - -The git object database ------------------------ - -Let's start a new project and create a small amount of history: - ------------------------------------------------- -$ mkdir test-project -$ cd test-project -$ git init -Initialized empty Git repository in .git/ -$ echo 'hello world' > file.txt -$ git add . -$ git commit -a -m "initial commit" -Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7 - create mode 100644 file.txt -$ echo 'hello world!' >file.txt -$ git commit -a -m "add emphasis" -Created commit c4d59f390b9cfd4318117afde11d601c1085f241 ------------------------------------------------- - -What are the 40 digits of hex that git responded to the commit with? - -We saw in part one of the tutorial that commits have names like this. -It turns out that every object in the git history is stored under -such a 40-digit hex name. That name is the SHA1 hash of the object's -contents; among other things, this ensures that git will never store -the same data twice (since identical data is given an identical SHA1 -name), and that the contents of a git object will never change (since -that would change the object's name as well). - -It is expected that the content of the commit object you created while -following the example above generates a different SHA1 hash than -the one shown above because the commit object records the time when -it was created and the name of the person performing the commit. - -We can ask git about this particular object with the cat-file -command. Don't copy the 40 hex digits from this example but use those -from your own version. Note that you can shorten it to only a few -characters to save yourself typing all 40 hex digits: - ------------------------------------------------- -$ git-cat-file -t 54196cc2 -commit -$ git-cat-file commit 54196cc2 -tree 92b8b694ffb1675e5975148e1121810081dbdffe -author J. Bruce Fields 1143414668 -0500 -committer J. Bruce Fields 1143414668 -0500 - -initial commit ------------------------------------------------- - -A tree can refer to one or more "blob" objects, each corresponding to -a file. In addition, a tree can also refer to other tree objects, -thus creating a directory hierarchy. You can examine the contents of -any tree using ls-tree (remember that a long enough initial portion -of the SHA1 will also work): - ------------------------------------------------- -$ git ls-tree 92b8b694 -100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad file.txt ------------------------------------------------- - -Thus we see that this tree has one file in it. The SHA1 hash is a -reference to that file's data: - ------------------------------------------------- -$ git cat-file -t 3b18e512 -blob ------------------------------------------------- - -A "blob" is just file data, which we can also examine with cat-file: - ------------------------------------------------- -$ git cat-file blob 3b18e512 -hello world ------------------------------------------------- - -Note that this is the old file data; so the object that git named in -its response to the initial tree was a tree with a snapshot of the -directory state that was recorded by the first commit. - -All of these objects are stored under their SHA1 names inside the git -directory: - ------------------------------------------------- -$ find .git/objects/ -.git/objects/ -.git/objects/pack -.git/objects/info -.git/objects/3b -.git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad -.git/objects/92 -.git/objects/92/b8b694ffb1675e5975148e1121810081dbdffe -.git/objects/54 -.git/objects/54/196cc2703dc165cbd373a65a4dcf22d50ae7f7 -.git/objects/a0 -.git/objects/a0/423896973644771497bdc03eb99d5281615b51 -.git/objects/d0 -.git/objects/d0/492b368b66bdabf2ac1fd8c92b39d3db916e59 -.git/objects/c4 -.git/objects/c4/d59f390b9cfd4318117afde11d601c1085f241 ------------------------------------------------- - -and the contents of these files is just the compressed data plus a -header identifying their length and their type. The type is either a -blob, a tree, a commit, or a tag. - -The simplest commit to find is the HEAD commit, which we can find -from .git/HEAD: - ------------------------------------------------- -$ cat .git/HEAD -ref: refs/heads/master ------------------------------------------------- - -As you can see, this tells us which branch we're currently on, and it -tells us this by naming a file under the .git directory, which itself -contains a SHA1 name referring to a commit object, which we can -examine with cat-file: - ------------------------------------------------- -$ cat .git/refs/heads/master -c4d59f390b9cfd4318117afde11d601c1085f241 -$ git cat-file -t c4d59f39 -commit -$ git cat-file commit c4d59f39 -tree d0492b368b66bdabf2ac1fd8c92b39d3db916e59 -parent 54196cc2703dc165cbd373a65a4dcf22d50ae7f7 -author J. Bruce Fields 1143418702 -0500 -committer J. Bruce Fields 1143418702 -0500 - -add emphasis ------------------------------------------------- - -The "tree" object here refers to the new state of the tree: - ------------------------------------------------- -$ git ls-tree d0492b36 -100644 blob a0423896973644771497bdc03eb99d5281615b51 file.txt -$ git cat-file blob a0423896 -hello world! ------------------------------------------------- - -and the "parent" object refers to the previous commit: - ------------------------------------------------- -$ git-cat-file commit 54196cc2 -tree 92b8b694ffb1675e5975148e1121810081dbdffe -author J. Bruce Fields 1143414668 -0500 -committer J. Bruce Fields 1143414668 -0500 - -initial commit ------------------------------------------------- - -The tree object is the tree we examined first, and this commit is -unusual in that it lacks any parent. - -Most commits have only one parent, but it is also common for a commit -to have multiple parents. In that case the commit represents a -merge, with the parent references pointing to the heads of the merged -branches. - -Besides blobs, trees, and commits, the only remaining type of object -is a "tag", which we won't discuss here; refer to linkgit:git-tag[1] -for details. - -So now we know how git uses the object database to represent a -project's history: - - * "commit" objects refer to "tree" objects representing the - snapshot of a directory tree at a particular point in the - history, and refer to "parent" commits to show how they're - connected into the project history. - * "tree" objects represent the state of a single directory, - associating directory names to "blob" objects containing file - data and "tree" objects containing subdirectory information. - * "blob" objects contain file data without any other structure. - * References to commit objects at the head of each branch are - stored in files under .git/refs/heads/. - * The name of the current branch is stored in .git/HEAD. - -Note, by the way, that lots of commands take a tree as an argument. -But as we can see above, a tree can be referred to in many different -ways--by the SHA1 name for that tree, by the name of a commit that -refers to the tree, by the name of a branch whose head refers to that -tree, etc.--and most such commands can accept any of these names. - -In command synopses, the word "tree-ish" is sometimes used to -designate such an argument. - -The index file --------------- - -The primary tool we've been using to create commits is "git commit --a", which creates a commit including every change you've made to -your working tree. But what if you want to commit changes only to -certain files? Or only certain changes to certain files? - -If we look at the way commits are created under the cover, we'll see -that there are more flexible ways creating commits. - -Continuing with our test-project, let's modify file.txt again: - ------------------------------------------------- -$ echo "hello world, again" >>file.txt ------------------------------------------------- - -but this time instead of immediately making the commit, let's take an -intermediate step, and ask for diffs along the way to keep track of -what's happening: - ------------------------------------------------- -$ git diff ---- a/file.txt -+++ b/file.txt -@@ -1 +1,2 @@ - hello world! -+hello world, again -$ git add file.txt -$ git diff ------------------------------------------------- - -The last diff is empty, but no new commits have been made, and the -head still doesn't contain the new line: - ------------------------------------------------- -$ git-diff HEAD -diff --git a/file.txt b/file.txt -index a042389..513feba 100644 ---- a/file.txt -+++ b/file.txt -@@ -1 +1,2 @@ - hello world! -+hello world, again ------------------------------------------------- - -So "git diff" is comparing against something other than the head. -The thing that it's comparing against is actually the index file, -which is stored in .git/index in a binary format, but whose contents -we can examine with ls-files: - ------------------------------------------------- -$ git ls-files --stage -100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt -$ git cat-file -t 513feba2 -blob -$ git cat-file blob 513feba2 -hello world! -hello world, again ------------------------------------------------- - -So what our "git add" did was store a new blob and then put -a reference to it in the index file. If we modify the file again, -we'll see that the new modifications are reflected in the "git-diff" -output: - ------------------------------------------------- -$ echo 'again?' >>file.txt -$ git diff -index 513feba..ba3da7b 100644 ---- a/file.txt -+++ b/file.txt -@@ -1,2 +1,3 @@ - hello world! - hello world, again -+again? ------------------------------------------------- - -With the right arguments, git diff can also show us the difference -between the working directory and the last commit, or between the -index and the last commit: - ------------------------------------------------- -$ git diff HEAD -diff --git a/file.txt b/file.txt -index a042389..ba3da7b 100644 ---- a/file.txt -+++ b/file.txt -@@ -1 +1,3 @@ - hello world! -+hello world, again -+again? -$ git diff --cached -diff --git a/file.txt b/file.txt -index a042389..513feba 100644 ---- a/file.txt -+++ b/file.txt -@@ -1 +1,2 @@ - hello world! -+hello world, again ------------------------------------------------- - -At any time, we can create a new commit using "git commit" (without -the -a option), and verify that the state committed only includes the -changes stored in the index file, not the additional change that is -still only in our working tree: - ------------------------------------------------- -$ git commit -m "repeat" -$ git diff HEAD -diff --git a/file.txt b/file.txt -index 513feba..ba3da7b 100644 ---- a/file.txt -+++ b/file.txt -@@ -1,2 +1,3 @@ - hello world! - hello world, again -+again? ------------------------------------------------- - -So by default "git commit" uses the index to create the commit, not -the working tree; the -a option to commit tells it to first update -the index with all changes in the working tree. - -Finally, it's worth looking at the effect of "git add" on the index -file: - ------------------------------------------------- -$ echo "goodbye, world" >closing.txt -$ git add closing.txt ------------------------------------------------- - -The effect of the "git add" was to add one entry to the index file: - ------------------------------------------------- -$ git ls-files --stage -100644 8b9743b20d4b15be3955fc8d5cd2b09cd2336138 0 closing.txt -100644 513feba2e53ebbd2532419ded848ba19de88ba00 0 file.txt ------------------------------------------------- - -And, as you can see with cat-file, this new entry refers to the -current contents of the file: - ------------------------------------------------- -$ git cat-file blob 8b9743b2 -goodbye, world ------------------------------------------------- - -The "status" command is a useful way to get a quick summary of the -situation: - ------------------------------------------------- -$ git status -# On branch master -# Changes to be committed: -# (use "git reset HEAD ..." to unstage) -# -# new file: closing.txt -# -# Changed but not updated: -# (use "git add ..." to update what will be committed) -# -# modified: file.txt -# ------------------------------------------------- - -Since the current state of closing.txt is cached in the index file, -it is listed as "Changes to be committed". Since file.txt has -changes in the working directory that aren't reflected in the index, -it is marked "changed but not updated". At this point, running "git -commit" would create a commit that added closing.txt (with its new -contents), but that didn't modify file.txt. - -Also, note that a bare "git diff" shows the changes to file.txt, but -not the addition of closing.txt, because the version of closing.txt -in the index file is identical to the one in the working directory. - -In addition to being the staging area for new commits, the index file -is also populated from the object database when checking out a -branch, and is used to hold the trees involved in a merge operation. -See the link:core-tutorial.html[core tutorial] and the relevant man -pages for details. - -What next? ----------- - -At this point you should know everything necessary to read the man -pages for any of the git commands; one good place to start would be -with the commands mentioned in link:everyday.html[Everyday git]. You -should be able to find any unknown jargon in the -link:glossary.html[Glossary]. - -The link:user-manual.html[Git User's Manual] provides a more -comprehensive introduction to git. - -The link:cvs-migration.html[CVS migration] document explains how to -import a CVS repository into git, and shows how to use git in a -CVS-like way. - -For some interesting examples of git use, see the -link:howto-index.html[howtos]. - -For git developers, the link:core-tutorial.html[Core tutorial] goes -into detail on the lower-level git mechanisms involved in, for -example, creating a new commit. diff --git a/Documentation/tutorial.txt b/Documentation/tutorial.txt deleted file mode 100644 index e2bbda53f..000000000 --- a/Documentation/tutorial.txt +++ /dev/null @@ -1,584 +0,0 @@ -A tutorial introduction to git (for version 1.5.1 or newer) -=========================================================== - -This tutorial explains how to import a new project into git, make -changes to it, and share changes with other developers. - -If you are instead primarily interested in using git to fetch a project, -for example, to test the latest version, you may prefer to start with -the first two chapters of link:user-manual.html[The Git User's Manual]. - -First, note that you can get documentation for a command such as "git -diff" with: - ------------------------------------------------- -$ man git-diff ------------------------------------------------- - -It is a good idea to introduce yourself to git with your name and -public email address before doing any operation. The easiest -way to do so is: - ------------------------------------------------- -$ git config --global user.name "Your Name Comes Here" -$ git config --global user.email you@yourdomain.example.com ------------------------------------------------- - - -Importing a new project ------------------------ - -Assume you have a tarball project.tar.gz with your initial work. You -can place it under git revision control as follows. - ------------------------------------------------- -$ tar xzf project.tar.gz -$ cd project -$ git init ------------------------------------------------- - -Git will reply - ------------------------------------------------- -Initialized empty Git repository in .git/ ------------------------------------------------- - -You've now initialized the working directory--you may notice a new -directory created, named ".git". - -Next, tell git to take a snapshot of the contents of all files under the -current directory (note the '.'), with linkgit:git-add[1]: - ------------------------------------------------- -$ git add . ------------------------------------------------- - -This snapshot is now stored in a temporary staging area which git calls -the "index". You can permanently store the contents of the index in the -repository with linkgit:git-commit[1]: - ------------------------------------------------- -$ git commit ------------------------------------------------- - -This will prompt you for a commit message. You've now stored the first -version of your project in git. - -Making changes --------------- - -Modify some files, then add their updated contents to the index: - ------------------------------------------------- -$ git add file1 file2 file3 ------------------------------------------------- - -You are now ready to commit. You can see what is about to be committed -using linkgit:git-diff[1] with the --cached option: - ------------------------------------------------- -$ git diff --cached ------------------------------------------------- - -(Without --cached, linkgit:git-diff[1] will show you any changes that -you've made but not yet added to the index.) You can also get a brief -summary of the situation with linkgit:git-status[1]: - ------------------------------------------------- -$ git status -# On branch master -# Changes to be committed: -# (use "git reset HEAD ..." to unstage) -# -# modified: file1 -# modified: file2 -# modified: file3 -# ------------------------------------------------- - -If you need to make any further adjustments, do so now, and then add any -newly modified content to the index. Finally, commit your changes with: - ------------------------------------------------- -$ git commit ------------------------------------------------- - -This will again prompt your for a message describing the change, and then -record a new version of the project. - -Alternatively, instead of running `git add` beforehand, you can use - ------------------------------------------------- -$ git commit -a ------------------------------------------------- - -which will automatically notice any modified (but not new) files, add -them to the index, and commit, all in one step. - -A note on 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. - -Git tracks content not files ----------------------------- - -Many revision control systems provide an "add" command that tells the -system to start tracking changes to a new file. Git's "add" command -does something simpler and more powerful: `git add` is used both for new -and newly modified files, and in both cases it takes a snapshot of the -given files and stages that content in the index, ready for inclusion in -the next commit. - -Viewing project history ------------------------ - -At any point you can view the history of your changes using - ------------------------------------------------- -$ git log ------------------------------------------------- - -If you also want to see complete diffs at each step, use - ------------------------------------------------- -$ git log -p ------------------------------------------------- - -Often the overview of the change is useful to get a feel of -each step - ------------------------------------------------- -$ git log --stat --summary ------------------------------------------------- - -Managing branches ------------------ - -A single git repository can maintain multiple branches of -development. To create a new branch named "experimental", use - ------------------------------------------------- -$ git branch experimental ------------------------------------------------- - -If you now run - ------------------------------------------------- -$ git branch ------------------------------------------------- - -you'll get a list of all existing branches: - ------------------------------------------------- - experimental -* master ------------------------------------------------- - -The "experimental" branch is the one you just created, and the -"master" branch is a default branch that was created for you -automatically. The asterisk marks the branch you are currently on; -type - ------------------------------------------------- -$ git checkout experimental ------------------------------------------------- - -to switch to the experimental branch. Now edit a file, commit the -change, and switch back to the master branch: - ------------------------------------------------- -(edit file) -$ git commit -a -$ git checkout master ------------------------------------------------- - -Check that the change you made is no longer visible, since it was -made on the experimental branch and you're back on the master branch. - -You can make a different change on the master branch: - ------------------------------------------------- -(edit file) -$ git commit -a ------------------------------------------------- - -at this point the two branches have diverged, with different changes -made in each. To merge the changes made in experimental into master, run - ------------------------------------------------- -$ git merge experimental ------------------------------------------------- - -If the changes don't conflict, you're done. If there are conflicts, -markers will be left in the problematic files showing the conflict; - ------------------------------------------------- -$ git diff ------------------------------------------------- - -will show this. Once you've edited the files to resolve the -conflicts, - ------------------------------------------------- -$ git commit -a ------------------------------------------------- - -will commit the result of the merge. Finally, - ------------------------------------------------- -$ gitk ------------------------------------------------- - -will show a nice graphical representation of the resulting history. - -At this point you could delete the experimental branch with - ------------------------------------------------- -$ git branch -d experimental ------------------------------------------------- - -This command ensures that the changes in the experimental branch are -already in the current branch. - -If you develop on a branch crazy-idea, then regret it, you can always -delete the branch with - -------------------------------------- -$ git branch -D crazy-idea -------------------------------------- - -Branches are cheap and easy, so this is a good way to try something -out. - -Using git for collaboration ---------------------------- - -Suppose that Alice has started a new project with a git repository in -/home/alice/project, and that Bob, who has a home directory on the -same machine, wants to contribute. - -Bob begins with: - ------------------------------------------------- -$ git clone /home/alice/project myrepo ------------------------------------------------- - -This creates a new directory "myrepo" containing a clone of Alice's -repository. The clone is on an equal footing with the original -project, possessing its own copy of the original project's history. - -Bob then makes some changes and commits them: - ------------------------------------------------- -(edit files) -$ git commit -a -(repeat as necessary) ------------------------------------------------- - -When he's ready, he tells Alice to pull changes from the repository -at /home/bob/myrepo. She does this with: - ------------------------------------------------- -$ cd /home/alice/project -$ git pull /home/bob/myrepo master ------------------------------------------------- - -This merges the changes from Bob's "master" branch into Alice's -current branch. If Alice has made her own changes in the meantime, -then she may need to manually fix any conflicts. (Note that the -"master" argument in the above command is actually unnecessary, as it -is the default.) - -The "pull" command thus performs two operations: it fetches changes -from a remote branch, then merges them into the current branch. - -When you are working in a small closely knit group, it is not -unusual to interact with the same repository over and over -again. By defining 'remote' repository shorthand, you can make -it easier: - ------------------------------------------------- -$ git remote add bob /home/bob/myrepo ------------------------------------------------- - -With this, Alice can perform the first operation alone using the -"git fetch" command without merging them with her own branch, -using: - -------------------------------------- -$ git fetch bob -------------------------------------- - -Unlike the longhand form, when Alice fetches from Bob using a -remote repository shorthand set up with `git remote`, what was -fetched is stored in a remote tracking branch, in this case -`bob/master`. So after this: - -------------------------------------- -$ git log -p master..bob/master -------------------------------------- - -shows a list of all the changes that Bob made since he branched from -Alice's master branch. - -After examining those changes, Alice -could merge the changes into her master branch: - -------------------------------------- -$ git merge bob/master -------------------------------------- - -This `merge` can also be done by 'pulling from her own remote -tracking branch', like this: - -------------------------------------- -$ git pull . remotes/bob/master -------------------------------------- - -Note that git pull always merges into the current branch, -regardless of what else is given on the command line. - -Later, Bob can update his repo with Alice's latest changes using - -------------------------------------- -$ git pull -------------------------------------- - -Note that he doesn't need to give the path to Alice's repository; -when Bob cloned Alice's repository, git stored the location of her -repository in the repository configuration, and that location is -used for pulls: - -------------------------------------- -$ git config --get remote.origin.url -/home/alice/project -------------------------------------- - -(The complete configuration created by git-clone is visible using -"git config -l", and the linkgit:git-config[1] man page -explains the meaning of each option.) - -Git also keeps a pristine copy of Alice's master branch under the -name "origin/master": - -------------------------------------- -$ git branch -r - origin/master -------------------------------------- - -If Bob later decides to work from a different host, he can still -perform clones and pulls using the ssh protocol: - -------------------------------------- -$ git clone alice.org:/home/alice/project myrepo -------------------------------------- - -Alternatively, git has a native protocol, or can use rsync or http; -see linkgit:git-pull[1] for details. - -Git can also be used in a CVS-like mode, with a central repository -that various users push changes to; see linkgit:git-push[1] and -link:cvs-migration.html[git for CVS users]. - -Exploring history ------------------ - -Git history is represented as a series of interrelated commits. We -have already seen that the git log command can list those commits. -Note that first line of each git log entry also gives a name for the -commit: - -------------------------------------- -$ git log -commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 -Author: Junio C Hamano -Date: Tue May 16 17:18:22 2006 -0700 - - merge-base: Clarify the comments on post processing. -------------------------------------- - -We can give this name to git show to see the details about this -commit. - -------------------------------------- -$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 -------------------------------------- - -But there are other ways to refer to commits. You can use any initial -part of the name that is long enough to uniquely identify the commit: - -------------------------------------- -$ git show c82a22c39c # the first few characters of the name are - # usually enough -$ git show HEAD # the tip of the current branch -$ git show experimental # the tip of the "experimental" branch -------------------------------------- - -Every commit usually has one "parent" commit -which points to the previous state of the project: - -------------------------------------- -$ git show HEAD^ # to see the parent of HEAD -$ git show HEAD^^ # to see the grandparent of HEAD -$ git show HEAD~4 # to see the great-great grandparent of HEAD -------------------------------------- - -Note that merge commits may have more than one parent: - -------------------------------------- -$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^) -$ git show HEAD^2 # show the second parent of HEAD -------------------------------------- - -You can also give commits names of your own; after running - -------------------------------------- -$ git-tag v2.5 1b2e1d63ff -------------------------------------- - -you can refer to 1b2e1d63ff by the name "v2.5". If you intend to -share this name with other people (for example, to identify a release -version), you should create a "tag" object, and perhaps sign it; see -linkgit:git-tag[1] for details. - -Any git command that needs to know a commit can take any of these -names. For example: - -------------------------------------- -$ git diff v2.5 HEAD # compare the current HEAD to v2.5 -$ git branch stable v2.5 # start a new branch named "stable" based - # at v2.5 -$ git reset --hard HEAD^ # reset your current branch and working - # directory to its state at HEAD^ -------------------------------------- - -Be careful with that last command: in addition to losing any changes -in the working directory, it will also remove all later commits from -this branch. If this branch is the only branch containing those -commits, they will be lost. Also, don't use "git reset" on a -publicly-visible branch that other developers pull from, as it will -force needless merges on other developers to clean up the history. -If you need to undo changes that you have pushed, use linkgit:git-revert[1] -instead. - -The git grep command can search for strings in any version of your -project, so - -------------------------------------- -$ git grep "hello" v2.5 -------------------------------------- - -searches for all occurrences of "hello" in v2.5. - -If you leave out the commit name, git grep will search any of the -files it manages in your current directory. So - -------------------------------------- -$ git grep "hello" -------------------------------------- - -is a quick way to search just the files that are tracked by git. - -Many git commands also take sets of commits, which can be specified -in a number of ways. Here are some examples with git log: - -------------------------------------- -$ git log v2.5..v2.6 # commits between v2.5 and v2.6 -$ git log v2.5.. # commits since v2.5 -$ git log --since="2 weeks ago" # commits from the last 2 weeks -$ git log v2.5.. Makefile # commits since v2.5 which modify - # Makefile -------------------------------------- - -You can also give git log a "range" of commits where the first is not -necessarily an ancestor of the second; for example, if the tips of -the branches "stable-release" and "master" diverged from a common -commit some time ago, then - -------------------------------------- -$ git log stable..experimental -------------------------------------- - -will list commits made in the experimental branch but not in the -stable branch, while - -------------------------------------- -$ git log experimental..stable -------------------------------------- - -will show the list of commits made on the stable branch but not -the experimental branch. - -The "git log" command has a weakness: it must present commits in a -list. When the history has lines of development that diverged and -then merged back together, the order in which "git log" presents -those commits is meaningless. - -Most projects with multiple contributors (such as the linux kernel, -or git itself) have frequent merges, and gitk does a better job of -visualizing their history. For example, - -------------------------------------- -$ gitk --since="2 weeks ago" drivers/ -------------------------------------- - -allows you to browse any commits from the last 2 weeks of commits -that modified files under the "drivers" directory. (Note: you can -adjust gitk's fonts by holding down the control key while pressing -"-" or "+".) - -Finally, most commands that take filenames will optionally allow you -to precede any filename by a commit, to specify a particular version -of the file: - -------------------------------------- -$ git diff v2.5:Makefile HEAD:Makefile.in -------------------------------------- - -You can also use "git show" to see any such file: - -------------------------------------- -$ git show v2.5:Makefile -------------------------------------- - -Next Steps ----------- - -This tutorial should be enough to perform basic distributed revision -control for your projects. However, to fully understand the depth -and power of git you need to understand two simple ideas on which it -is based: - - * The object database is the rather elegant system used to - store the history of your project--files, directories, and - commits. - - * The index file is a cache of the state of a directory tree, - used to create commits, check out working directories, and - hold the various trees involved in a merge. - -link:tutorial-2.html[Part two of this tutorial] explains the object -database, the index file, and a few other odds and ends that you'll -need to make the most of git. - -If you don't want to continue with that right away, a few other -digressions that may be interesting at this point are: - - * linkgit:git-format-patch[1], linkgit:git-am[1]: These convert - series of git commits into emailed patches, and vice versa, - useful for projects such as the linux kernel which rely heavily - on emailed patches. - - * linkgit:git-bisect[1]: When there is a regression in your - project, one way to track down the bug is by searching through - the history to find the exact commit that's to blame. Git bisect - can help you perform a binary search for that commit. It is - smart enough to perform a close-to-optimal search even in the - case of complex non-linear history with lots of merged branches. - - * link:everyday.html[Everyday GIT with 20 Commands Or So] - - * link:cvs-migration.html[git for CVS users]. diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index e2db85015..fd8cdb625 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1993,7 +1993,7 @@ the right to push to the same repository. In that case, the correct solution is to retry the push after first updating your work by either a pull or a fetch followed by a rebase; see the <> and -link:cvs-migration.html[git for CVS users] for more. +linkgit:gitcvs-migration[7][git for CVS users] for more. [[setting-up-a-shared-repository]] Setting up a shared repository @@ -2002,7 +2002,7 @@ 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 -link:cvs-migration.html[git for CVS users] for instructions on how to +linkgit:gitcvs-migration[7][git for CVS users] for instructions on how to set this up. However, while there is nothing wrong with git's support for shared -- cgit v1.2.1