Skip to content

Translate Chapter2 "Git Basics" #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions book/02-git-basics/1-git-basics.asc
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
//////////////////////////
[[_git_basics_chapter]]
== Git Basics
//////////////////////////
== Git の基本

//////////////////////////
If you can read only one chapter to get going with Git, this is it.
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.
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.
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.
//////////////////////////
Git を使い始めるにあたってどれかひとつの章だけしか読めないとしたら、読むべきは本章です。
この章では、あなたが実際に Git を使う際に必要となる基本コマンドをすべて取り上げています。
本章を最後まで読めば、リポジトリの設定や初期化、ファイルの追跡、そして変更内容のステージやコミットなどができるようになるでしょう。
また、Git で特定のファイル (あるいは特定のファイルパターン) を無視させる方法やミスを簡単に取り消す方法、プロジェクトの歴史や各コミットの変更内容を見る方法、リモートリポジトリとの間でのプッシュやプルを行う方法についても説明します。

//////////////////////////
include::sections/getting-a-repository.asc[]
//////////////////////////
include::sections/getting-a-repository.asc[]

//////////////////////////
include::sections/recording-changes.asc[]
//////////////////////////
include::sections/recording-changes.asc[]

//////////////////////////
include::sections/viewing-history.asc[]
//////////////////////////
include::sections/viewing-history.asc[]

//////////////////////////
include::sections/undoing.asc[]
//////////////////////////
include::sections/undoing.asc[]

//////////////////////////
include::sections/remotes.asc[]
//////////////////////////
include::sections/remotes.asc[]

//////////////////////////
include::sections/tagging.asc[]
//////////////////////////
include::sections/tagging.asc[]

//////////////////////////
include::sections/aliases.asc[]
//////////////////////////
include::sections/aliases.asc[]

//////////////////////////
=== Summary
//////////////////////////
=== まとめ

//////////////////////////
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.
Next, we'll cover Git's killer feature: its branching model.
//////////////////////////
これで、ローカルでの Git の基本的な操作がこなせるようになりました。リポジトリの作成やクローン、リポジトリへの変更・ステージ・コミット、リポジトリのこれまでの変更履歴の閲覧などです。
次は、Git の強力な機能であるブランチモデルについて説明しましょう。
87 changes: 86 additions & 1 deletion book/02-git-basics/sections/aliases.asc
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
//////////////////////////
[[_git_aliases]]
=== Git Aliases
//////////////////////////
=== Git エイリアス

//////////////////////////
(((aliases)))
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.
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.
//////////////////////////
(((aliases)))
この章で進めてきたGitの基本に関する説明を終える前に、ひとつヒントを教えましょう。Gitの使い勝手をシンプルに、簡単に、わかりやすくしてくれる、エイリアスです。

//////////////////////////
Git doesn't automatically infer your command if you type it in partially.
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)))
Here are a couple of examples you may want to set up:
//////////////////////////
Git は、コマンドの一部だけが入力された状態でそのコマンドを自動的に推測することはありません。
Git の各コマンドをいちいち全部入力するのがいやなら、 `git config` でコマンドのエイリアスを設定することができます。(((git commands, config)))
たとえばこんなふうに設定すると便利かもしれません。

//////////////////////////
[source,console]
----
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
----
//////////////////////////
[source,console]
----
$ git config --global alias.co checkout
Expand All @@ -17,35 +38,86 @@ $ git config --global alias.ci commit
$ git config --global alias.st status
----

//////////////////////////
This means that, for example, instead of typing `git commit`, you just need to type `git ci`.
As you go on using Git, you'll probably use other commands frequently as well; don't hesitate to create new aliases.
//////////////////////////
こうすると、たとえば `git commit` と同じことが単に `git ci` と入力するだけでできるようになります。
Git を使い続けるにつれて、よく使うコマンドがさらに増えてくることでしょう。
そんな場合は、きにせずどんどん新しいエイリアスを作りましょう。

//////////////////////////
This technique can also be very useful in creating commands that you think should exist.
For example, to correct the usability problem you encountered with unstaging a file, you can add your own unstage alias to Git:
//////////////////////////
このテクニックは、「こんなことできたらいいな」というコマンドを作る際にも便利です。
たとえば、ステージを解除するときにどうしたらいいかいつも迷うという人なら、
こんなふうに自分で unstage エイリアスを追加してしまえばいいのです。

//////////////////////////
[source,console]
----
$ git config --global alias.unstage 'reset HEAD --'
----
//////////////////////////
[source,console]
----
$ git config --global alias.unstage 'reset HEAD --'
----

//////////////////////////
This makes the following two commands equivalent:
//////////////////////////
こうすれば、次のふたつのコマンドが同じ意味となります。

//////////////////////////
[source,console]
----
$ git unstage fileA
$ git reset HEAD fileA
----
//////////////////////////
[source,console]
----
$ git unstage fileA
$ git reset HEAD fileA
----

//////////////////////////
This seems a bit clearer.
It's also common to add a `last` command, like this:
//////////////////////////
少しはわかりやすくなりましたね。あるいは、こんなふうに `last` コマンドを追加することもできます。

//////////////////////////
[source,console]
----
$ git config --global alias.last 'log -1 HEAD'
----
//////////////////////////
[source,console]
----
$ git config --global alias.last 'log -1 HEAD'
----

//////////////////////////
This way, you can see the last commit easily:
//////////////////////////
こうすれば、直近のコミットの情報を見ることができます。

//////////////////////////
[source,console]
----
$ git last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel <dreamer3@example.com>
Date: Tue Aug 26 19:48:51 2008 +0800

test for current head

Signed-off-by: Scott Chacon <schacon@example.com>
----
//////////////////////////
[source,console]
----
$ git last
Expand All @@ -58,12 +130,25 @@ Date: Tue Aug 26 19:48:51 2008 +0800
Signed-off-by: Scott Chacon <schacon@example.com>
----

//////////////////////////
As you can tell, Git simply replaces the new command with whatever you alias it for.
However, maybe you want to run an external command, rather than a Git subcommand.
In that case, you start the command with a `!` character.
This is useful if you write your own tools that work with a Git repository.
We can demonstrate by aliasing `git visual` to run `gitk`:

//////////////////////////
Git が単に新しいコマンドをエイリアスで置き換えていることがわかります。
しかし、時には Git のサブコマンドではなく外部コマンドを実行したくなることもあるでしょう。
そんな場合は、コマンドの先頭に `!` をつけます。
これは、Git リポジトリ上で動作する自作のツールを書くときに便利です。
例として、`git visual` で `gitk` が起動するようにしてみましょう。

//////////////////////////
[source,console]
----
$ git config --global alias.visual "!gitk"
----
//////////////////////////
[source,console]
----
$ git config --global alias.visual "!gitk"
Expand Down
81 changes: 80 additions & 1 deletion book/02-git-basics/sections/getting-a-repository.asc
Original file line number Diff line number Diff line change
@@ -1,64 +1,143 @@
//////////////////////////
[[_getting_a_repo]]
=== Getting a Git Repository
//////////////////////////
[[_getting_a_repo]]
=== Git リポジトリの取得

//////////////////////////
You can get a Git project using two main approaches.
The first takes an existing project or directory and imports it into Git.
The second clones an existing Git repository from another server.
//////////////////////////
Git プロジェクトを取得するには、大きく二通りの方法があります。
ひとつは既存のプロジェクトやディレクトリを Git にインポートする方法、
そしてもうひとつは既存の Git リポジトリを別のサーバーからクローンする方法です。

//////////////////////////
==== Initializing a Repository in an Existing Directory
//////////////////////////
==== 既存のディレクトリでのリポジトリの初期化

//////////////////////////
If you're starting to track an existing project in Git, you need to go to the project's directory and type
//////////////////////////
既存のプロジェクトを Git で管理し始めるときは、そのプロジェクトのディレクトリに移動して次のように打ち込みます。


//////////////////////////
[source,console]
----
$ git init
----
//////////////////////////
[source,console]
----
$ git init
----

//////////////////////////
This creates a new subdirectory named `.git` that contains all of your necessary repository files – a Git repository skeleton.
At this point, nothing in your project is tracked yet.
(See <<_git_internals>> for more information about exactly what files are contained in the `.git` directory you just created.)(((git commands, init)))
//////////////////////////
これを実行すると `.git` という名前の新しいサブディレクトリが作られ、リポジトリに必要なすべてのファイル (Git リポジトリのスケルトン) がその中に格納されます。
この時点では、まだプロジェクト内のファイルは一切管理対象になっていません
(今作った `.git` ディレクトリに実際のところどんなファイルが含まれているのかについての詳細な情報は、<<_git_internals>>を参照ください)。(((git commands, init)))

//////////////////////////
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.
You can accomplish that with a few `git add` commands that specify the files you want to track, followed by a `git commit`:
//////////////////////////
空のディレクトリではなくすでに存在するファイルのバージョン管理を始めたい場合は、まずそのファイルを監視対象に追加してから最初のコミットをすることになります。この場合は、追加したいファイルについて `git add` コマンドを実行したあとで `git commit` コマンドを行います。

//////////////////////////
[source,console]
----
$ git add *.c
$ git add LICENSE
$ git commit -m 'initial project version'
----
//////////////////////////
[source,console]
----
$ git add *.c
$ git add LICENSE
$ git commit -m 'initial project version'
----

//////////////////////////
We'll go over what these commands do in just a minute.
At this point, you have a Git repository with tracked files and an initial commit.
//////////////////////////
これが実際のところどういう意味なのかについては後で説明します。ひとまずこの時点で、監視対象のファイルを持つ Git リポジトリができあがり最初のコミットまで済んだことになります。

//////////////////////////
[[_git_cloning]]
==== Cloning an Existing Repository
//////////////////////////
[[_git_cloning]]
==== 既存のリポジトリのクローン

//////////////////////////
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`.
If you're familiar with other VCS systems such as Subversion, you'll notice that the command is "clone" and not "checkout".
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.
Every version of every file for the history of the project is pulled down by default when you run `git clone`.
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).

//////////////////////////
既存の Git リポジトリ (何か協力したいと思っているプロジェクトなど) のコピーを取得したい場合に使うコマンドが、`git clone` です。
Subversion などの他の VCS を使っている人なら「"checkout" じゃなくて "clone" なのか」と気になることでしょう。
これは重要な違いです。ワーキングコピーを取得するのではなく、Git はサーバーが保持しているデータをほぼすべてコピーするのです。
そのプロジェクトのすべてのファイルのすべての歴史が、デフォルトでは `git clone` で手元にやってきます。
実際、もし仮にサーバーのディスクが壊れてしまったとしても、どこかのクライアントに残っているクローンをサーバーに戻せばクローンした時点まで多くの場合は復元できるでしょう(サーバーサイドのフックなど一部の情報は失われてしまいますが、これまでのバージョン管理履歴はすべてそこに残っています。<<_git_on_the_server>>で詳しく説明します)。

//////////////////////////
You clone a repository with `git clone [url]`.(((git commands, clone)))
For example, if you want to clone the Git linkable library called libgit2, you can do so like this:
//////////////////////////
リポジトリをクローンするには `git clone [url]` とします。(((git commands, clone)))
たとえば、多言語へのバインディングが可能なGitライブラリであるlibgitをクローンする場合は次のようになります。

//////////////////////////
[source,console]
----
$ git clone https://github.com/libgit2/libgit2
----
//////////////////////////
[source,console]
----
$ git clone https://github.com/libgit2/libgit2
----

//////////////////////////
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.
If you go into the new `libgit2` directory, you'll see the project files in there, ready to be worked on or used.
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:
//////////////////////////
これは、まず``libgit2''というディレクトリを作成してその中で `.git` ディレクトリを初期化し、リポジトリのすべてのデータを引き出し、そして最新バージョンの作業コピーをチェックアウトします。
新しくできた `libgit2` ディレクトリに入ると、プロジェクトのファイルをごらんいただけます。
もし``libgit2''ではない別の名前のディレクトリにクローンしたいのなら、コマンドラインオプションでディレクトリ名を指定します。

//////////////////////////
[source,console]
----
$ git clone https://github.com/libgit2/libgit2 mylibgit
----
//////////////////////////
[source,console]
----
$ git clone https://github.com/libgit2/libgit2 mylibgit
----

//////////////////////////
That command does the same thing as the previous one, but the target directory is called `mylibgit`.
//////////////////////////
このコマンドは先ほどと同じ処理をしますが、ディレクトリ名は `mylibgit` となります。

//////////////////////////
Git has a number of different transfer protocols you can use.
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.
<<_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.
//////////////////////////
Git では、さまざまな転送プロトコルを使用することができます。先ほどの例では `https://` プロトコルを使用しましたが、`git://` や `user@server:/path/to/repo.git` といった形式を使うこともできます。これらは SSH プロトコルを使用します。<<_git_on_the_server>>で、サーバー側で準備できるすべてのアクセス方式についての利点と欠点を説明します。
Loading