Skip to content
Closed
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
17 changes: 9 additions & 8 deletions book/02-git-basics/1-git-basics.asc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[[_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 完成各种工作中将要使用的各种基本命令。
在学习完本章之后,您应该能够配置并初始化一个仓库(repository)、开始或停止跟踪(track)文件、暂存(stage)或提交(commit)更改。
本章也将向您演示如何配置 Git 来忽略指定的文件和文件模式、如何迅速而简单地撤销不小心的操作、如何浏览您的项目的历史版本以及不同提交(commits)间的差异、如何向您的远程仓库推送(push)以及如何从您的远程仓库拉取(pull)文件。

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

Expand All @@ -20,7 +20,8 @@ include::sections/tagging.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 的杀手级特性:分支模型。
56 changes: 28 additions & 28 deletions book/02-git-basics/sections/getting-a-repository.asc
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[[_getting_a_repo]]
=== Getting a Git Repository
=== 获取项目的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
----

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` 文件夹中包含了哪些文件的信息。)(((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 仓库来进行版本控制的话,您应该开始跟踪这些文件并提交。
您可通过 `git add` 命令来实现对指定文件的跟踪,然后执行 `git commit` 提交:

[source,console]
----
Expand All @@ -28,37 +28,37 @@ $ 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
==== 克隆一个现有的仓库

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` 命令。
如果您对其他的 VCS 系统(比如说Subversion)很熟悉,请留心一下您所使用的命令是"clone"而不是"checkout"
这是 Git 区别于其他版本控制系统的一个重要特性,Git 克隆的是该Git仓库服务器上的几乎所有数据,而不是仅仅复制完成您的工作所需要文件。
当您执行 `git clone` 命令的时候,默认配置下远程 Git 仓库中的每一个文件的每一个版本都将被复制下来。
事实上,如果您的服务器的磁盘坏掉了,您通常可以使用任何一个克隆下来的用户端来重建服务器上的仓库(虽然可能会丢失某些服务器端的挂钩设置,但是所有版本的数据仍在,有关细节请参考 <<_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 的可链接库 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` 文件夹、从远程仓库复制下所有数据放入 `.git` 文件夹,然后从中读取最新版本的文件的拷贝。
如果您进入到这个新建的 `libgit2` 文件夹,您会发现所有的项目文件已经在里面了,准备就绪等待后续的开发和使用。
如果您想在克隆远程仓库的时候,自定义本地仓库的名字,您可以使用如下命令:

[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://` 协议或者使用 SSH 传输协议,比如 `user@server:path/to/repo.git`
<<_git_on_the_server>>将会介绍所有这些协议在服务器端如何配置使用,以及各种方式之间的利弊
4 changes: 2 additions & 2 deletions status.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"sections/installing.asc": 0
},
"02-git-basics": {
"1-git-basics.asc": 0,
"1-git-basics.asc": 100,
"sections/aliases.asc": 0,
"sections/getting-a-repository.asc": 0,
"sections/getting-a-repository.asc": 100,
"sections/recording-changes.asc": 0,
"sections/remotes.asc": 0,
"sections/tagging.asc": 0,
Expand Down