Skip to content

Commit afa47c8

Browse files
committed
Merge pull request #3 from harupong/ch02
Translate Chapter2 "Git Basics"
2 parents 63a025e + 19646aa commit afa47c8

File tree

9 files changed

+1969
-27
lines changed

9 files changed

+1969
-27
lines changed

book/02-git-basics/1-git-basics.asc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,63 @@
1+
//////////////////////////
12
[[_git_basics_chapter]]
23
== Git Basics
4+
//////////////////////////
5+
== Git の基本
36
7+
//////////////////////////
48
If you can read only one chapter to get going with Git, this is it.
59
This chapter covers every basic command you need to do the vast majority of the things you'll eventually spend your time doing with Git.
610
By the end of the chapter, you should be able to configure and initialize a repository, begin and stop tracking files, and stage and commit changes.
711
We'll also show you how to set up Git to ignore certain files and file patterns, how to undo mistakes quickly and easily, how to browse the history of your project and view changes between commits, and how to push and pull from remote repositories.
12+
//////////////////////////
13+
Git を使い始めるにあたってどれかひとつの章だけしか読めないとしたら、読むべきは本章です。
14+
この章では、あなたが実際に Git を使う際に必要となる基本コマンドをすべて取り上げています。
15+
本章を最後まで読めば、リポジトリの設定や初期化、ファイルの追跡、そして変更内容のステージやコミットなどができるようになるでしょう。
16+
また、Git で特定のファイル (あるいは特定のファイルパターン) を無視させる方法やミスを簡単に取り消す方法、プロジェクトの歴史や各コミットの変更内容を見る方法、リモートリポジトリとの間でのプッシュやプルを行う方法についても説明します。
817
18+
//////////////////////////
19+
include::sections/getting-a-repository.asc[]
20+
//////////////////////////
921
include::sections/getting-a-repository.asc[]
1022
23+
//////////////////////////
24+
include::sections/recording-changes.asc[]
25+
//////////////////////////
1126
include::sections/recording-changes.asc[]
1227
28+
//////////////////////////
29+
include::sections/viewing-history.asc[]
30+
//////////////////////////
1331
include::sections/viewing-history.asc[]
1432
33+
//////////////////////////
34+
include::sections/undoing.asc[]
35+
//////////////////////////
1536
include::sections/undoing.asc[]
1637
38+
//////////////////////////
39+
include::sections/remotes.asc[]
40+
//////////////////////////
1741
include::sections/remotes.asc[]
1842
43+
//////////////////////////
44+
include::sections/tagging.asc[]
45+
//////////////////////////
1946
include::sections/tagging.asc[]
2047
48+
//////////////////////////
49+
include::sections/aliases.asc[]
50+
//////////////////////////
2151
include::sections/aliases.asc[]
2252
53+
//////////////////////////
2354
=== Summary
55+
//////////////////////////
56+
=== まとめ
2457
58+
//////////////////////////
2559
At this point, you can do all the basic local Git operations – creating or cloning a repository, making changes, staging and committing those changes, and viewing the history of all the changes the repository has been through.
2660
Next, we'll cover Git's killer feature: its branching model.
61+
//////////////////////////
62+
これで、ローカルでの Git の基本的な操作がこなせるようになりました。リポジトリの作成やクローン、リポジトリへの変更・ステージ・コミット、リポジトリのこれまでの変更履歴の閲覧などです。
63+
次は、Git の強力な機能であるブランチモデルについて説明しましょう。

book/02-git-basics/sections/aliases.asc

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1+
//////////////////////////
12
[[_git_aliases]]
23
=== Git Aliases
4+
//////////////////////////
5+
=== Git エイリアス
36
7+
//////////////////////////
48
(((aliases)))
59
Before we finish this chapter on basic Git, there's just one little tip that can make your Git experience simpler, easier, and more familiar: aliases.
610
We won't refer to them or assume you've used them later in the book, but you should probably know how to use them.
11+
//////////////////////////
12+
(((aliases)))
13+
この章で進めてきたGitの基本に関する説明を終える前に、ひとつヒントを教えましょう。Gitの使い勝手をシンプルに、簡単に、わかりやすくしてくれる、エイリアスです。
714
15+
//////////////////////////
816
Git doesn't automatically infer your command if you type it in partially.
917
If you don't want to type the entire text of each of the Git commands, you can easily set up an alias for each command using `git config`.(((git commands, config)))
1018
Here are a couple of examples you may want to set up:
19+
//////////////////////////
20+
Git は、コマンドの一部だけが入力された状態でそのコマンドを自動的に推測することはありません。
21+
Git の各コマンドをいちいち全部入力するのがいやなら、 `git config` でコマンドのエイリアスを設定することができます。(((git commands, config)))
22+
たとえばこんなふうに設定すると便利かもしれません。
1123
24+
//////////////////////////
25+
[source,console]
26+
----
27+
$ git config --global alias.co checkout
28+
$ git config --global alias.br branch
29+
$ git config --global alias.ci commit
30+
$ git config --global alias.st status
31+
----
32+
//////////////////////////
1233
[source,console]
1334
----
1435
$ git config --global alias.co checkout
@@ -17,35 +38,86 @@ $ git config --global alias.ci commit
1738
$ git config --global alias.st status
1839
----
1940
41+
//////////////////////////
2042
This means that, for example, instead of typing `git commit`, you just need to type `git ci`.
2143
As you go on using Git, you'll probably use other commands frequently as well; don't hesitate to create new aliases.
44+
//////////////////////////
45+
こうすると、たとえば `git commit` と同じことが単に `git ci` と入力するだけでできるようになります。
46+
Git を使い続けるにつれて、よく使うコマンドがさらに増えてくることでしょう。
47+
そんな場合は、きにせずどんどん新しいエイリアスを作りましょう。
2248
49+
//////////////////////////
2350
This technique can also be very useful in creating commands that you think should exist.
2451
For example, to correct the usability problem you encountered with unstaging a file, you can add your own unstage alias to Git:
52+
//////////////////////////
53+
このテクニックは、「こんなことできたらいいな」というコマンドを作る際にも便利です。
54+
たとえば、ステージを解除するときにどうしたらいいかいつも迷うという人なら、
55+
こんなふうに自分で unstage エイリアスを追加してしまえばいいのです。
2556
57+
//////////////////////////
58+
[source,console]
59+
----
60+
$ git config --global alias.unstage 'reset HEAD --'
61+
----
62+
//////////////////////////
2663
[source,console]
2764
----
2865
$ git config --global alias.unstage 'reset HEAD --'
2966
----
3067
68+
//////////////////////////
3169
This makes the following two commands equivalent:
70+
//////////////////////////
71+
こうすれば、次のふたつのコマンドが同じ意味となります。
3272
73+
//////////////////////////
74+
[source,console]
75+
----
76+
$ git unstage fileA
77+
$ git reset HEAD fileA
78+
----
79+
//////////////////////////
3380
[source,console]
3481
----
3582
$ git unstage fileA
3683
$ git reset HEAD fileA
3784
----
3885
86+
//////////////////////////
3987
This seems a bit clearer.
4088
It's also common to add a `last` command, like this:
89+
//////////////////////////
90+
少しはわかりやすくなりましたね。あるいは、こんなふうに `last` コマンドを追加することもできます。
4191
92+
//////////////////////////
93+
[source,console]
94+
----
95+
$ git config --global alias.last 'log -1 HEAD'
96+
----
97+
//////////////////////////
4298
[source,console]
4399
----
44100
$ git config --global alias.last 'log -1 HEAD'
45101
----
46102
103+
//////////////////////////
47104
This way, you can see the last commit easily:
105+
//////////////////////////
106+
こうすれば、直近のコミットの情報を見ることができます。
107+
108+
//////////////////////////
109+
[source,console]
110+
----
111+
$ git last
112+
commit 66938dae3329c7aebe598c2246a8e6af90d04646
113+
Author: Josh Goebel <dreamer3@example.com>
114+
Date: Tue Aug 26 19:48:51 2008 +0800
48115
116+
test for current head
117+
118+
Signed-off-by: Scott Chacon <schacon@example.com>
119+
----
120+
//////////////////////////
49121
[source,console]
50122
----
51123
$ git last
@@ -58,12 +130,25 @@ Date: Tue Aug 26 19:48:51 2008 +0800
58130
Signed-off-by: Scott Chacon <schacon@example.com>
59131
----
60132
133+
//////////////////////////
61134
As you can tell, Git simply replaces the new command with whatever you alias it for.
62135
However, maybe you want to run an external command, rather than a Git subcommand.
63136
In that case, you start the command with a `!` character.
64137
This is useful if you write your own tools that work with a Git repository.
65138
We can demonstrate by aliasing `git visual` to run `gitk`:
66-
139+
//////////////////////////
140+
Git が単に新しいコマンドをエイリアスで置き換えていることがわかります。
141+
しかし、時には Git のサブコマンドではなく外部コマンドを実行したくなることもあるでしょう。
142+
そんな場合は、コマンドの先頭に `!` をつけます。
143+
これは、Git リポジトリ上で動作する自作のツールを書くときに便利です。
144+
例として、`git visual` で `gitk` が起動するようにしてみましょう。
145+
146+
//////////////////////////
147+
[source,console]
148+
----
149+
$ git config --global alias.visual "!gitk"
150+
----
151+
//////////////////////////
67152
[source,console]
68153
----
69154
$ git config --global alias.visual "!gitk"
Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,143 @@
1+
//////////////////////////
12
[[_getting_a_repo]]
23
=== Getting a Git Repository
4+
//////////////////////////
5+
[[_getting_a_repo]]
6+
=== Git リポジトリの取得
37
8+
//////////////////////////
49
You can get a Git project using two main approaches.
510
The first takes an existing project or directory and imports it into Git.
611
The second clones an existing Git repository from another server.
12+
//////////////////////////
13+
Git プロジェクトを取得するには、大きく二通りの方法があります。
14+
ひとつは既存のプロジェクトやディレクトリを Git にインポートする方法、
15+
そしてもうひとつは既存の Git リポジトリを別のサーバーからクローンする方法です。
716
17+
//////////////////////////
818
==== Initializing a Repository in an Existing Directory
19+
//////////////////////////
20+
==== 既存のディレクトリでのリポジトリの初期化
921
22+
//////////////////////////
1023
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+
1127
28+
//////////////////////////
29+
[source,console]
30+
----
31+
$ git init
32+
----
33+
//////////////////////////
1234
[source,console]
1335
----
1436
$ git init
1537
----
1638
39+
//////////////////////////
1740
This creates a new subdirectory named `.git` that contains all of your necessary repository files – a Git repository skeleton.
1841
At this point, nothing in your project is tracked yet.
1942
(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)))
2047
48+
//////////////////////////
2149
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.
2250
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` コマンドを行います。
2353
54+
//////////////////////////
55+
[source,console]
56+
----
57+
$ git add *.c
58+
$ git add LICENSE
59+
$ git commit -m 'initial project version'
60+
----
61+
//////////////////////////
2462
[source,console]
2563
----
2664
$ git add *.c
2765
$ git add LICENSE
2866
$ git commit -m 'initial project version'
2967
----
3068
69+
//////////////////////////
3170
We'll go over what these commands do in just a minute.
3271
At this point, you have a Git repository with tracked files and an initial commit.
72+
//////////////////////////
73+
これが実際のところどういう意味なのかについては後で説明します。ひとまずこの時点で、監視対象のファイルを持つ Git リポジトリができあがり最初のコミットまで済んだことになります。
3374
75+
//////////////////////////
3476
[[_git_cloning]]
3577
==== Cloning an Existing Repository
78+
//////////////////////////
79+
[[_git_cloning]]
80+
==== 既存のリポジトリのクローン
3681
82+
//////////////////////////
3783
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`.
3884
If you're familiar with other VCS systems such as Subversion, you'll notice that the command is "clone" and not "checkout".
3985
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.
4086
Every version of every file for the history of the project is pulled down by default when you run `git clone`.
4187
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+
//////////////////////////
4396
You clone a repository with `git clone [url]`.(((git commands, clone)))
4497
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をクローンする場合は次のようになります。
45101
102+
//////////////////////////
103+
[source,console]
104+
----
105+
$ git clone https://github.com/libgit2/libgit2
106+
----
107+
//////////////////////////
46108
[source,console]
47109
----
48110
$ git clone https://github.com/libgit2/libgit2
49111
----
50112
113+
//////////////////////////
51114
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.
52115
If you go into the new `libgit2` directory, you'll see the project files in there, ready to be worked on or used.
53116
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''ではない別の名前のディレクトリにクローンしたいのなら、コマンドラインオプションでディレクトリ名を指定します。
54121
122+
//////////////////////////
123+
[source,console]
124+
----
125+
$ git clone https://github.com/libgit2/libgit2 mylibgit
126+
----
127+
//////////////////////////
55128
[source,console]
56129
----
57130
$ git clone https://github.com/libgit2/libgit2 mylibgit
58131
----
59132
133+
//////////////////////////
60134
That command does the same thing as the previous one, but the target directory is called `mylibgit`.
135+
//////////////////////////
136+
このコマンドは先ほどと同じ処理をしますが、ディレクトリ名は `mylibgit` となります。
61137
138+
//////////////////////////
62139
Git has a number of different transfer protocols you can use.
63140
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.
64141
<<_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

Comments
 (0)