Revision 1 as of 2011-04-05 16:45:22
|Deletions are marked like this.||Additions are marked like this.|
|Line 3:||Line 3:|
|''(This page is part 2 of 9 of the [[Tutorial]] series. Previous part is [[TutorialInstall]], next part is [[TutorialClone]])''||''(This page is part of the [[Tutorial]] series. Previous part is [[TutorialInstall]], next part is [[TutorialClone]])''|
Tutorial - Initializing a Repository
You have followed TutorialInstall to install Mercurial already, right? Good!
In Mercurial, we do all of our work inside a repository. A repository is a directory that contains all of the source files that we want to keep history of, along with complete histories of those source files (inside the .hg directory — see UnderstandingMercurial).
Unlike some version control systems, you can create a repository in any directory you have write permissions to. All you have to do is initialize the repository, which will create a .hg subdirectory, and add some files to the repository.
To do this, we use the init command.1
Let's init a small "hello, world" repository in our file system.
(telephoto: /tmp) mkdir repo (telephoto: /tmp) cd repo /tmp/repo (telephoto: /tmp/repo) ls (telephoto: /tmp/repo) hg init
We can now see that our new repo has the .hg directory:
(telephoto: /tmp/repo) ls -a ./ ../ .hg/
We can now add some files to mercurial. In this example we're creating the files after we've initialized the repository, but that's not important in mercurial. One of the great things about mercurial is that it's easy to add version control to an existing directory structure. In either case, we just use "hg add" to place the files under version control.
(telephoto: /tmp/repo) touch hello.txt (telephoto: /tmp/repo) ls hello.txt (telephoto: /tmp/repo) ls -a ./ ../ hello.txt .hg/ (telephoto: /tmp/repo) hg add hello.txt
After adding the files they're not really "in" mercurial yet. For that we have to commit them:
(telephoto: /tmp/repo) hg commit -m "adding initial version of hello.txt" (telephoto: /tmp/repo) ls -a ./ ../ hello.txt .hg/ (telephoto: /tmp/repo)
Nothing obvious changes about the files now that they've been committed, but we now know that this version of our files is preserved in the repository. We should now find a directory called my-hello in our current directory:
A common way to use mercurial is to clone an existing repository that someone else has created. The next lesson shows you how to do that, in TutorialClone.