我们将尝试在本次实验中探索其中的差异。

如果命令行参数未提供,更改“Hello, World”程序来接受一个 默认值。

添加更改

现在添加此次更改到 Git 的暂存区。

现在给“Hello, World”程序添加一行注释。

  1. # Default is "World"
  2. name = ARGV.first || "World"
  3. puts "Hello, #{name}!"

检查当前状态

  1. # On branch master
  2. # Changes to be committed:
  3. # (use "git reset HEAD <file>..." to unstage)
  4. #
  5. # modified: hello.rb
  6. # Changes not staged for commit:
  7. # (use "git add <file>..." to update what will be committed)
  8. # (use "git checkout -- <file>..." to discard changes in working directory)
  9. #
  10. # modified: hello.rb

注意 hello.rb 在状态中被列了两次。第一次更改已被暂存,且 准备提交。第二次更改还未暂存。如果你现在提交,那么注释不 会保存到仓库中。

让我们试试看。

提交暂存的更改,然后重新检查状态。

  1. $ git commit -m "Added a default value"
  2. $ git status

你应该看到:

添加第二次更改

现在添加第二次更改到暂存区,然后执行 git status

  1. $ git status

注意:我们使用当前目录(.)作为要添加的文件。这是一种 添加当前目录及其子目录下所有更改文件的习惯简写方式。 但因为它添加所有东东,所以在做 add . 前检查状态是一 个好主意,只是为了确定你没有添加不想要的文件。

我想你已经明白了 add . 这个技巧,但为了安全在余下的 教程中我们将继续直接添加文件。

你应该看到:

  1. $ git status
  2. # On branch master
  3. # Changes to be committed:
  4. # (use "git reset HEAD <file>..." to unstage)
  5. #
  6. # modified: hello.rb
  7. #