|
| 1 | +////////////////////////// |
1 | 2 | [[_getting_a_repo]]
|
2 | 3 | === Getting a Git Repository
|
| 4 | +////////////////////////// |
| 5 | +[[_getting_a_repo]] |
| 6 | +=== Git リポジトリの取得 |
3 | 7 |
|
| 8 | +////////////////////////// |
4 | 9 | You can get a Git project using two main approaches.
|
5 | 10 | The first takes an existing project or directory and imports it into Git.
|
6 | 11 | The second clones an existing Git repository from another server.
|
| 12 | +////////////////////////// |
| 13 | +Git プロジェクトを取得するには、大きく二通りの方法があります。 |
| 14 | +ひとつは既存のプロジェクトやディレクトリを Git にインポートする方法、 |
| 15 | +そしてもうひとつは既存の Git リポジトリを別のサーバーからクローンする方法です。 |
7 | 16 |
|
| 17 | +////////////////////////// |
8 | 18 | ==== Initializing a Repository in an Existing Directory
|
| 19 | +////////////////////////// |
| 20 | +==== 既存のディレクトリでのリポジトリの初期化 |
9 | 21 |
|
| 22 | +////////////////////////// |
10 | 23 | If you're starting to track an existing project in Git, you need to go to the project's directory and type
|
| 24 | +////////////////////////// |
| 25 | +既存のプロジェクトを Git で管理し始めるときは、そのプロジェクトのディレクトリに移動して次のように打ち込みます。 |
| 26 | +
|
11 | 27 |
|
| 28 | +////////////////////////// |
| 29 | +[source,console] |
| 30 | +---- |
| 31 | +$ git init |
| 32 | +---- |
| 33 | +////////////////////////// |
12 | 34 | [source,console]
|
13 | 35 | ----
|
14 | 36 | $ git init
|
15 | 37 | ----
|
16 | 38 |
|
| 39 | +////////////////////////// |
17 | 40 | This creates a new subdirectory named `.git` that contains all of your necessary repository files – a Git repository skeleton.
|
18 | 41 | At this point, nothing in your project is tracked yet.
|
19 | 42 | (See <<_git_internals>> for more information about exactly what files are contained in the `.git` directory you just created.)(((git commands, init)))
|
| 43 | +////////////////////////// |
| 44 | +これを実行すると `.git` という名前の新しいサブディレクトリが作られ、リポジトリに必要なすべてのファイル (Git リポジトリのスケルトン) がその中に格納されます。 |
| 45 | +この時点では、まだプロジェクト内のファイルは一切管理対象になっていません |
| 46 | +(今作った `.git` ディレクトリに実際のところどんなファイルが含まれているのかについての詳細な情報は、<<_git_internals>>を参照ください)。(((git commands, init))) |
20 | 47 |
|
| 48 | +////////////////////////// |
21 | 49 | If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit.
|
22 | 50 | You can accomplish that with a few `git add` commands that specify the files you want to track, followed by a `git commit`:
|
| 51 | +////////////////////////// |
| 52 | +空のディレクトリではなくすでに存在するファイルのバージョン管理を始めたい場合は、まずそのファイルを監視対象に追加してから最初のコミットをすることになります。この場合は、追加したいファイルについて `git add` コマンドを実行したあとで `git commit` コマンドを行います。 |
23 | 53 |
|
| 54 | +////////////////////////// |
| 55 | +[source,console] |
| 56 | +---- |
| 57 | +$ git add *.c |
| 58 | +$ git add LICENSE |
| 59 | +$ git commit -m 'initial project version' |
| 60 | +---- |
| 61 | +////////////////////////// |
24 | 62 | [source,console]
|
25 | 63 | ----
|
26 | 64 | $ git add *.c
|
27 | 65 | $ git add LICENSE
|
28 | 66 | $ git commit -m 'initial project version'
|
29 | 67 | ----
|
30 | 68 |
|
| 69 | +////////////////////////// |
31 | 70 | We'll go over what these commands do in just a minute.
|
32 | 71 | At this point, you have a Git repository with tracked files and an initial commit.
|
| 72 | +////////////////////////// |
| 73 | +これが実際のところどういう意味なのかについては後で説明します。ひとまずこの時点で、監視対象のファイルを持つ Git リポジトリができあがり最初のコミットまで済んだことになります。 |
33 | 74 |
|
| 75 | +////////////////////////// |
34 | 76 | [[_git_cloning]]
|
35 | 77 | ==== Cloning an Existing Repository
|
| 78 | +////////////////////////// |
| 79 | +[[_git_cloning]] |
| 80 | +==== 既存のリポジトリのクローン |
36 | 81 |
|
| 82 | +////////////////////////// |
37 | 83 | If you want to get a copy of an existing Git repository – for example, a project you'd like to contribute to – the command you need is `git clone`.
|
38 | 84 | If you're familiar with other VCS systems such as Subversion, you'll notice that the command is "clone" and not "checkout".
|
39 | 85 | This is an important distinction – instead of getting just a working copy, Git receives a full copy of nearly all data that the server has.
|
40 | 86 | Every version of every file for the history of the project is pulled down by default when you run `git clone`.
|
41 | 87 | In fact, if your server disk gets corrupted, you can often use nearly any of the clones on any client to set the server back to the state it was in when it was cloned (you may lose some server-side hooks and such, but all the versioned data would be there – see <<_git_on_the_server>> for more details).
|
42 |
| - |
| 88 | +////////////////////////// |
| 89 | +既存の Git リポジトリ (何か協力したいと思っているプロジェクトなど) のコピーを取得したい場合に使うコマンドが、`git clone` です。 |
| 90 | +Subversion などの他の VCS を使っている人なら「"checkout" じゃなくて "clone" なのか」と気になることでしょう。 |
| 91 | +これは重要な違いです。ワーキングコピーを取得するのではなく、Git はサーバーが保持しているデータをほぼすべてコピーするのです。 |
| 92 | +そのプロジェクトのすべてのファイルのすべての歴史が、デフォルトでは `git clone` で手元にやってきます。 |
| 93 | +実際、もし仮にサーバーのディスクが壊れてしまったとしても、どこかのクライアントに残っているクローンをサーバーに戻せばクローンした時点まで多くの場合は復元できるでしょう(サーバーサイドのフックなど一部の情報は失われてしまいますが、これまでのバージョン管理履歴はすべてそこに残っています。<<_git_on_the_server>>で詳しく説明します)。 |
| 94 | +
|
| 95 | +////////////////////////// |
43 | 96 | You clone a repository with `git clone [url]`.(((git commands, clone)))
|
44 | 97 | For example, if you want to clone the Git linkable library called libgit2, you can do so like this:
|
| 98 | +////////////////////////// |
| 99 | +リポジトリをクローンするには `git clone [url]` とします。(((git commands, clone))) |
| 100 | +たとえば、多言語へのバインディングが可能なGitライブラリであるlibgitをクローンする場合は次のようになります。 |
45 | 101 |
|
| 102 | +////////////////////////// |
| 103 | +[source,console] |
| 104 | +---- |
| 105 | +$ git clone https://github.com/libgit2/libgit2 |
| 106 | +---- |
| 107 | +////////////////////////// |
46 | 108 | [source,console]
|
47 | 109 | ----
|
48 | 110 | $ git clone https://github.com/libgit2/libgit2
|
49 | 111 | ----
|
50 | 112 |
|
| 113 | +////////////////////////// |
51 | 114 | That creates a directory named ``libgit2'', initializes a `.git` directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version.
|
52 | 115 | If you go into the new `libgit2` directory, you'll see the project files in there, ready to be worked on or used.
|
53 | 116 | If you want to clone the repository into a directory named something other than ``libgit2'', you can specify that as the next command-line option:
|
| 117 | +////////////////////////// |
| 118 | +これは、まず``libgit2''というディレクトリを作成してその中で `.git` ディレクトリを初期化し、リポジトリのすべてのデータを引き出し、そして最新バージョンの作業コピーをチェックアウトします。 |
| 119 | +新しくできた `libgit2` ディレクトリに入ると、プロジェクトのファイルをごらんいただけます。 |
| 120 | +もし``libgit2''ではない別の名前のディレクトリにクローンしたいのなら、コマンドラインオプションでディレクトリ名を指定します。 |
54 | 121 |
|
| 122 | +////////////////////////// |
| 123 | +[source,console] |
| 124 | +---- |
| 125 | +$ git clone https://github.com/libgit2/libgit2 mylibgit |
| 126 | +---- |
| 127 | +////////////////////////// |
55 | 128 | [source,console]
|
56 | 129 | ----
|
57 | 130 | $ git clone https://github.com/libgit2/libgit2 mylibgit
|
58 | 131 | ----
|
59 | 132 |
|
| 133 | +////////////////////////// |
60 | 134 | That command does the same thing as the previous one, but the target directory is called `mylibgit`.
|
| 135 | +////////////////////////// |
| 136 | +このコマンドは先ほどと同じ処理をしますが、ディレクトリ名は `mylibgit` となります。 |
61 | 137 |
|
| 138 | +////////////////////////// |
62 | 139 | Git has a number of different transfer protocols you can use.
|
63 | 140 | The previous example uses the `https://` protocol, but you may also see `git://` or `user@server:path/to/repo.git`, which uses the SSH transfer protocol.
|
64 | 141 | <<_git_on_the_server>> will introduce all of the available options the server can set up to access your Git repository and the pros and cons of each.
|
| 142 | +////////////////////////// |
| 143 | +Git では、さまざまな転送プロトコルを使用することができます。先ほどの例では `https://` プロトコルを使用しましたが、`git://` や `user@server:/path/to/repo.git` といった形式を使うこともできます。これらは SSH プロトコルを使用します。<<_git_on_the_server>>で、サーバー側で準備できるすべてのアクセス方式についての利点と欠点を説明します。 |
0 commit comments