diff --git a/.gitignore b/.gitignore index c9e7c5fa..93e9c046 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ output/* *#* .#* *~ +.bundle +.local +.bash_history +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..212a93e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM ubuntu + +RUN apt update + +RUN apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev -y + +# Install rbenv +RUN git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv +RUN echo '# rbenv setup' > /etc/profile.d/rbenv.sh +RUN echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh +RUN echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh +RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh +RUN chmod +x /etc/profile.d/rbenv.sh + +# install ruby-build +RUN mkdir /usr/local/rbenv/plugins +RUN git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build + +ENV RBENV_ROOT /usr/local/rbenv + +ENV PATH $RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +ENV RUBY_VERSION 3.2.0 +RUN rbenv install $RUBY_VERSION +RUN rbenv global $RUBY_VERSION +ENV LANG C.UTF-8 + +RUN ruby -v + +RUN gem install bundler -v '2.4.1' +RUN bundle install \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..21ce9771 --- /dev/null +++ b/Gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true +#ruby '3.2.0' +source "https://rubygems.org/" + +gem 'rake', '~> 13.0'# (13.0.6) +gem 'ultraviolet', '~> 1.0' +gem 'rdiscount', '~> 2.2' +gem 'builder', '~> 3.2' +gem 'wkhtmltopdf-binary' +gem 'pdfkit' + diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..3debe478 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,24 @@ +GEM + remote: https://rubygems.org/ + specs: + builder (3.2.4) + plist (3.6.0) + rake (13.0.6) + rdiscount (2.2.7) + textpow (1.4.0) + plist (>= 3.0.1) + ultraviolet (1.0.1) + textpow (>= 1.3.0) + +PLATFORMS + aarch64-linux + arm64-darwin-22 + +DEPENDENCIES + builder (~> 3.2) + rake (~> 13.0) + rdiscount (~> 2.2) + ultraviolet (~> 1.0) + +BUNDLED WITH + 2.4.1 diff --git a/README.md b/README.md new file mode 100644 index 00000000..282d1b07 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Git Community Book 中译本 + +图书在线阅读网址:https://gitbook.lkiuhui998.com + +原始仓库地址:https://github.com/schacon/gitbook + +作者: + +* [Scott Chacon](https://scottchacon.com/) + +* Emil Sit + +译者: + +* [Peter Liu](http://liuhui998.com) +* [Liu Wei](http://blog.liuw.name) + +* [Wendal](http://wendal.net) +* [Jiancong Guo](http://www.cbpm-gw.com) + + + + diff --git a/Rakefile b/Rakefile index 9d1b23b8..44d7762b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ -require 'script/merge' -require 'script/html' -require 'script/pdf' -require 'script/prince' \ No newline at end of file +require './script/merge' +require './script/html' +require './script/pdf' +require './script/pdf1' +require './script/prince' diff --git a/layout/book_index_template.html b/layout/book_index_template.html index 466b9b13..da03dfa0 100644 --- a/layout/book_index_template.html +++ b/layout/book_index_template.html @@ -105,37 +105,15 @@

新手指南

$('.footer').corner(); }); - - - + - - - - - -
- -
- - diff --git a/layout/chapter_template.html b/layout/chapter_template.html index d97c5d29..d934613b 100644 --- a/layout/chapter_template.html +++ b/layout/chapter_template.html @@ -54,35 +54,16 @@ - - - - - - + - - - -
- -
- diff --git a/layout/pdf_template.html b/layout/pdf_template.html index d6c6a46b..4a7f7789 100644 --- a/layout/pdf_template.html +++ b/layout/pdf_template.html @@ -78,8 +78,8 @@

中文版 Maintainer / Editor

liuhui998 (liuhui998@gmail.com),(http://liuhui998.com)
liu Wei (liuw@liuw.name),(http://blog.liuw.name)
- Wendal Chen(wendal1985@gmail.com),(http://sunfarms.net/myblog)
- Jiancong Guo(guojiancong0121@gmail.com),(http://www.cbpm-gw.com)
+ Wendal Chen(wendal1985@gmail.com),(http://wendal.net)
+ Jiancong Guo(guojiancong0121@gmail.com),(http://www.cbpm-gw.com)

中文版网址

diff --git a/script/html.rb b/script/html.rb index 81293524..3545ae44 100644 --- a/script/html.rb +++ b/script/html.rb @@ -8,6 +8,13 @@ #MIN_SIZE = 1200 MIN_SIZE = 800 +# Fix for new ruby version don't have exists? function. +class File + def self.exists?(file_name) + return File.exist?(file_name) + end +end + def do_replacements(html, type = :html) # highlight code @@ -51,7 +58,7 @@ def do_replacements(html, type = :html) desc 'Create the HTML version' task :html => :merge do - if File.exists?('output/full_book.markdown') + if File.exist?('output/full_book.markdown') output = File.new('output/full_book.markdown').read output = RDiscount.new(output).to_html diff --git a/script/pdf1.rb b/script/pdf1.rb new file mode 100644 index 00000000..f92fed21 --- /dev/null +++ b/script/pdf1.rb @@ -0,0 +1,24 @@ +desc 'Cria um arquivo pdf à partir do html gerado' +require 'pdfkit' + +task :pdf1 => :html do + + PDFKit.configure do |config| + config.default_options = { + enable_local_file_access: true, + } + end + + html = File.new("output/index.html").read + kit = PDFKit.new(html, page_width: '235', page_height: '177.8') + kit.stylesheets << 'layout/second.css' + kit.stylesheets << 'layout/mac_classic.css' + + # Get an inline PDF + pdf = kit.to_pdf + + # Save the PDF to a file + file = kit.to_file('output/book.pdf') + + `open output/book.pdf` +end diff --git a/text_zh/01_Introduction/0_ Introduction.markdown b/text_zh/01_Introduction/0_ Introduction.markdown index 1c34fa0b..1c4d3b7e 100644 --- a/text_zh/01_Introduction/0_ Introduction.markdown +++ b/text_zh/01_Introduction/0_ Introduction.markdown @@ -8,7 +8,7 @@ 此书将以介绍Git如何存储数据做为开始,让你了解它和其它版本控制系统有什么不同的背景。这大约要花你20分钟的时间。 -接下来,我们会讲一些Git的**基本用法**,那些你将在90%的时间都在使用的命令。这些东东能给一个不错的使用的基础,也许这些命令就是你将使用的全部命令。这一节大约会你30分钟的时间来读。 +接下来,我们会讲一些Git的**基本用法**,那些你将在90%的时间都在使用的命令。这些东东能给一个不错的使用的基础,也许这些命令就是你将使用的全部命令。这一节大约会花你30分钟的时间来读。 其后,我们会讲一些稍微复杂的**Git中级用法**,这些用法也许会替换掉前面的基本用法。在你了解前面的基本用法后, 这些看起来像魔术一样的命令,你可能会用起来很爽。 diff --git a/text_zh/08_Basic_Branching_and_Merging/0_ Basic_Branching_and_Merging.markdown b/text_zh/08_Basic_Branching_and_Merging/0_ Basic_Branching_and_Merging.markdown index 45dd8072..8f698429 100644 --- a/text_zh/08_Basic_Branching_and_Merging/0_ Basic_Branching_and_Merging.markdown +++ b/text_zh/08_Basic_Branching_and_Merging/0_ Basic_Branching_and_Merging.markdown @@ -55,7 +55,7 @@ $ git branch -d experimental -git branch -d只能删除那些已经被当前分支的合并的分支. 如果你要强制删除某个分支的话就用git branch –D;下面假设你要强制删除一个叫”crazy-idea”的分支: +git branch -d只能删除那些已经被当前分支的合并的分支。如果你要强制删除某个分支的话就用git branch –D;下面假设你要强制删除一个叫“crazy-idea”的分支: $ git branch -D crazy-idea diff --git a/text_zh/11_Distributed_Workflows_Clone_Fetch_Push/0_ Distributed_Workflows_Clone_Fetch_Push.markdown b/text_zh/11_Distributed_Workflows_Clone_Fetch_Push/0_ Distributed_Workflows_Clone_Fetch_Push.markdown index 5cf9c1af..7faf8d3a 100644 --- a/text_zh/11_Distributed_Workflows_Clone_Fetch_Push/0_ Distributed_Workflows_Clone_Fetch_Push.markdown +++ b/text_zh/11_Distributed_Workflows_Clone_Fetch_Push/0_ Distributed_Workflows_Clone_Fetch_Push.markdown @@ -1,7 +1,7 @@ ## 分布式的工作流程 ## 假设Alice现在开始了一个新项目,在/home/alice/project建了一个新的git -仓库(repository);另一个叫Bob的工作目录也在同一台机器,他要提交代码。 +仓库(repository);另外Bob的工作目录也在同一台机器,他要提交代码。 Bob 执行了这样的命令: @@ -42,7 +42,7 @@ git pull命令执行两个操作: 它从远程分支(remote branch)抓取修改 $ git remote add bob /home/bob/myrepo -这样,Alic可以用"git fetch"" 来执行"git pull"前半部分的工作, +这样,Alic可以用"git fetch"来执行"git pull"前半部分的工作, 但是这条命令并不会把抓下来的修改合并到当前分支里。 $ git fetch bob @@ -227,20 +227,15 @@ branch..remote, 和remote..push等选项的解释. $ git push ssh://yourserver.com/~you/proj.git +master -Normally whenever a branch head in a public repository is modified, it -is modified to point to a descendant of the commit that it pointed to -before. By forcing a push in this situation, you break that convention. +通常不论公共仓库的分支是否被修改,他都被修改为指向原来指向的提交(commit) +跟随的下一个提交(commit)。如果在这种情况下强制地推送,你就破坏了之前的约定。 +尽管如此,这也是一种通常的用法来简单地发布一系列正在修正的补丁,并且只要你 +通知了其他的开发者你打算怎样操作这个分支,这也是一种可以接受的折中办法。 -Nevertheless, this is a common practice for people that need a simple -way to publish a work-in-progress patch series, and it is an acceptable -compromise as long as you warn other developers that this is how you -intend to manage the branch. - -It's also possible for a push to fail in this way when other people have -the right to push to the same repository. In that case, the correct -solution is to retry the push after first updating your work: either by a -pull, or by a fetch followed by a rebase; see the next section and -linkgit:gitcvs-migration[7] for more. +一个推送(push)也可能因为其他人有向这个仓库(repository)推送的权利而失败。 +在这种情况下,正确地解决办法是首先用"pull"命令或者"fetch"命令和"rebase" +命令更新你的代码,然后重新尝试推送(push);更详细的了解请看下一部分和 +linkgit:gitcvs-migration[7]。 [gitcast:c8-dist-workflow]("GitCast #8: Distributed Workflow") diff --git a/text_zh/12a_Ignoring_Files/0_Ignoring_Files.markdown b/text_zh/12a_Ignoring_Files/0_Ignoring_Files.markdown index ab67d5b7..b7958a5b 100644 --- a/text_zh/12a_Ignoring_Files/0_Ignoring_Files.markdown +++ b/text_zh/12a_Ignoring_Files/0_Ignoring_Files.markdown @@ -24,7 +24,7 @@ 你可以点这里 linkgit:gitignore[5] 查看一下详细的语法解释. 你也可以把".gitignore" 这个文件放到工作树(working tree)里的其它目录中,这就会在它和它的子目录起忽略(ignore) -指定文件的作用。`.gitignor`文件同样可以像其它文件一样加到项目仓库里( 直接用 +指定文件的作用。`.gitignore`文件同样可以像其它文件一样加到项目仓库里( 直接用 `git add .gitignore` 和 `git commit`等命令), 这样项目里的其它开发者也能共享同一套忽略 文件规则。 diff --git a/text_zh/19_Finding_in_Git_Grep/0_ Finding_in_Git_Grep.markdown b/text_zh/19_Finding_in_Git_Grep/0_ Finding_in_Git_Grep.markdown index faf43ad5..3ac92e90 100644 --- a/text_zh/19_Finding_in_Git_Grep/0_ Finding_in_Git_Grep.markdown +++ b/text_zh/19_Finding_in_Git_Grep/0_ Finding_in_Git_Grep.markdown @@ -34,7 +34,7 @@ wrapper.c:89:void *xmmap(void *start, size_t length, -如果我们想只显示文件名, 我们可以使用'--name-onley'选项: +如果我们想只显示文件名, 我们可以使用'--name-only'选项: $>git grep --name-only xmmap config.c @@ -111,4 +111,4 @@ 译者注: 就是"与"条件搜索和"或"条件搜索可以组合使用. - \ No newline at end of file + diff --git a/text_zh/28_Finding_Issues_Git_Blame/0_ Finding_Issues_Git_Blame.markdown b/text_zh/28_Finding_Issues_Git_Blame/0_ Finding_Issues_Git_Blame.markdown index 48cdeb06..2e70bf16 100644 --- a/text_zh/28_Finding_Issues_Git_Blame/0_ Finding_Issues_Git_Blame.markdown +++ b/text_zh/28_Finding_Issues_Git_Blame/0_ Finding_Issues_Git_Blame.markdown @@ -3,6 +3,7 @@ 如果你要查看文件的每个部分是谁修改的, 那么 linkgit:git-blame[1] 就是不二选择. 只要运行'git blame [filename]', 你就会得到整个文件的每一行的详细修改信息:包括SHA串,日期和作者: 译者注: Git采用SHA1做为hash签名算法, 在本书中,作者为了表达方便,常常使用SHA来代指SHA1. 如果没有特别说明, 本书中的SHA就是SHA1的代称. + $ git blame sha1_file.c ... 0fcfd160 (Linus Torvalds 2005-04-18 13:04:43 -0700 8) */ diff --git a/text_zh/31_Git_Hooks/0_ Git_Hooks.markdown b/text_zh/31_Git_Hooks/0_ Git_Hooks.markdown index 605bf095..4ad3dfd6 100755 --- a/text_zh/31_Git_Hooks/0_ Git_Hooks.markdown +++ b/text_zh/31_Git_Hooks/0_ Git_Hooks.markdown @@ -1,66 +1,55 @@ ## Git Hooks ## -钩子(hooks)是一些在"$GIT-DIR/hooks"目录的脚本, 在被特定的事件(certain points)触发后被调用。当"git init"命令被调用后, 一些非常有用的示例钩子文件(hooks)被拷到新仓库的hooks目录中; 但是在默认情况下这些钩子(hooks)是不生效的。 把这些钩子文件(hooks)的".sample"文件名后缀去掉就可以使它们生效了。 +钩子(hooks)是一些在`$GIT-DIR/hooks`目录的脚本, 在被特定的事件(certain points)触发后被调用。当`git init`命令被调用后, 一些非常有用的示例钩子脚本被拷到新仓库的hooks目录中; 但是在默认情况下它们是不生效的。 把这些钩子文件的".sample"文件名后缀去掉就可以使它们生效。 ### applypatch-msg ### GIT_DIR/hooks/applypatch-msg -当'git-am'命令执行时,这个钩子就被调用。它只有一个参数:就是存有提交消息(commit log message)的文件的名字。如果钩子的执行结果是非零,那么补丁(patch)就不会被应用(apply)。 +这个钩子是由`git am`命令调用的。它只有一个参数:就是存有将要被应用的补丁(patch)的提交消息(commit log message)的文件名。如果钩子的返回值不是`0`,那么`git am`就会放弃对补丁的应用(apply the patch)。 -The hook is allowed to edit the message file in place, and can be used to -normalize the message into some project standard format (if the project has one). -It can also be used to refuse the commit after inspecting the message file. -The default applypatch-msg hook, when enabled, runs the commit-msg hook, if the -latter is enabled. -这个钩子用于在其它地方编辑提交消息,并且可以把这些消息规范成项目的标准格式(如果项目些类的标准的话)。它也可以在分析(inspect)完消息文件后拒绝此次提交(commit)。在默认情况下,当 applypatch-msg 钩子被启用时。。。。 +这个钩子可以在工作时(译注:也就是在`git am`运行时)编辑提交(commit)信息文件(message file)。它的一个用途是把提交(commit)信息规范化,使得其符合一些项目的标准(如果有的话)。它也可以用来在分析(inspect)完消息文件后拒绝某个提交(commit)。 + + +如果默认的`applypatch-msg.sample`钩子被启用,它会调用`commit-msg`钩子(如果它也被启用的话)。 -() ### pre-applypatch ### GIT_DIR/hooks/pre-applypatch -当'git-am'命令执行时,这个钩子就被调用。它没有参数,并且是在一个补丁(patch)被应用后还未提交(commit)前被调用。如果钩子的执行结果是非零,那么刚才应用的补丁(patch)就不会被提交。 +这个钩子是由`git am`命令调用的。它不需要参数,并且是在一个补丁(patch)被应用后还未提交(commit)前被调用。如果钩子的返回值不是`0``,那么刚才应用的补丁(patch)就不会被提交。 + -It can be used to inspect the current working tree and refuse to make a commit -if it does not pass certain test. -The default pre-applypatch hook, when enabled, runs the pre-commit hook, if the -latter is enabled. +它可以用于检查当前的工作树(译注:此时补丁已经被应用但没有被提交),如果补丁不能通过测试就拒绝此次提交(commit)。 -它用于检查当前的工作树,当提交的补丁不能通过特定的测试就拒绝将它提交(commit)进仓库。 -() + +如果默认的`pre-applypatch.sample`钩子被启用,它会调用`pre-commit`钩子(如果它也被启用的话)。 ### post-applypatch ### GIT_DIR/hooks/post-applypatch -This hook is invoked by 'git-am'. It takes no parameter, -and is invoked after the patch is applied and a commit is made. -当'git-am'命令执行时,这个钩子就被调用。它没有参数,并且是在一个补丁(patch)被应用且在完成提交(commit)情况下被调用。 +这个钩子是由`git am`命令调用的。它不需要参数,并且是在一个补丁(patch)被应用且在完成提交(commit)情况下被调用。 -This hook is meant primarily for notification, and cannot affect -the outcome of 'git-am'. -这个钩子的主要用途是通知提示(notification),它并不会影响'git-am'的执行和输出。 +这个钩子主要用来通知(notification),它并不会影响`git-am`的执行结果。 ### pre-commit ### GIT_DIR/hooks/pre-commit -这个钩子被 'git-commit' 命令调用, 而且可以通过在命令中添加`\--no-verify` 参数来跳过。这个钩子没有参数,在得到提交消息和开始提交(commit)前被调用。如果钩子执行结果是非零,那么 'git-commit' 命令就会中止执行。 +这个钩子被 `git commit` 命令调用, 而且可以通过在命令中添加`\--no-verify` 参数来跳过。这个钩子不需要参数,在得到提交消息和开始提交(commit)前被调用。如果钩子返回值不是`0`,那么 `git commit` 命令就会中止执行。 -译注:此钩子可以用来在提交前检查代码错误(运行类似lint的程序)。 +译注:这个钩子可以用来在提交前检查代码错误(例如运行lint程序)。 -当默认的'pre-commit'钩子开启时,如果它发现文件尾部有空白行,那么就会中止此次提交。 +当默认的`pre-commit`钩子被启用时,如果它发现文件尾部有空白行,那么就会中止此次提交。 译注:新版的默认钩子和这里所说有所有不同。 -All the 'git-commit' hooks are invoked with the environment -variable `GIT_EDITOR=:` if the command will not bring up an editor -to modify the commit message. +如果(进行`git commit`的)命令没有制定一个编辑器来修改提交信息(commit message),任何的 `git-commit` 钩子(译注:即无论是否自带)被调用时都会带上环境变量`GIT_EDITOR=:` 下面是一个运行 Rspec 测试的 Ruby 脚本,如果没有通过这个测试,那么不允许提交(commit)。 @@ -90,33 +79,29 @@ to modify the commit message. GIT_DIR/hooks/prepare-commit-msg -当'git-commit'命令执行时:在编辑器(editor)启动前,默认提交消息准备好后,这个钩子就被调用。 +执行`git commit`命令后,在默认提交消息准备好后但编辑器(editor)启动前,这个钩子就被调用。 It takes one to three parameters. The first is the name of the file -that the commit log message. The second is the source of the commit -message, and can be: `message` (if a `-m` or `-F` option was -given); `template` (if a `-t` option was given or the -configuration option `commit.template` is set); `merge` (if the -commit is a merge or a `.git/MERGE_MSG` file exists); `squash` -(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by -a commit SHA1 (if a `-c`, `-C` or `\--amend` option was given). -它有三个参数。第一个是提交消息文件的名字。第二个是提交消息的来源,它可以是:(). + +它接受一到三个参数。第一个包含了提交消息的文本文件的名字。第二个是提交消息的来源,它可以是: +* `message`(如果指定了`-m`或者`-F`选项) +* `template`(如果指定了`-t`选项,或者在设置(译注:即`git config`)中开启了`commit.template`选项) +* `merge`(如果本次提交(commit)是一次合并(merge),或者存在文件`.git/MERGE_MSG`) +* `squash`(如果存在文件`.git/SQUASH_MSG`) +* `commit` 并且第三个参数是一个提交(commit)的SHA1值(如果指定了`-c`,`-C`或者`\--amend`选项) -如果钩子的执行結果是非零的话,那么'git-commit'命令就会被中止执行。 +如果钩子的返回值不是`0`,那么`git commit`命令就会被中止执行。 -The purpose of the hook is to edit the message file in place, and -it is not suppressed by the `\--no-verify` option. A non-zero exit -means a failure of the hook and aborts the commit. It should not -be used as replacement for pre-commit hook. +这个钩子的目的是用来在工作时编辑信息文件,并且不会被`\--no-verify`选项略过。一个非`0`值意味着钩子工作失败,会终止提交(abort the commit)。它不应该用来作为`pre-commit`钩子的替代。 -The sample `prepare-commit-msg` hook that comes with git comments -out the `Conflicts:` part of a merge's commit message. +git提供的样本`prepare-commit-msg.sample`会把当前合并提交信息(a merge's commit message)中的`Conflicts:`部分注释掉。 +#Harry-Chen 校对至此# ### commit-msg ### @@ -373,4 +358,4 @@ for the user. ### 参考 ### -[Git Hooks](http://www.kernel.org/pub/software/scm/git/docs/githooks.html) * http://probablycorey.wordpress.com/2008/03/07/git-hooks-make-me-giddy/ \ No newline at end of file +[Git Hooks](http://www.kernel.org/pub/software/scm/git/docs/githooks.html) * http://probablycorey.wordpress.com/2008/03/07/git-hooks-make-me-giddy/