我们将尝试在本次实验中探索其中的差异。
如果命令行参数未提供,更改“Hello, World”程序来接受一个 默认值。
添加更改
现在添加此次更改到 Git 的暂存区。
现在给“Hello, World”程序添加一行注释。
# Default is "World"
name = ARGV.first || "World"
puts "Hello, #{name}!"
检查当前状态
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.rb
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: hello.rb
注意 hello.rb 在状态中被列了两次。第一次更改已被暂存,且 准备提交。第二次更改还未暂存。如果你现在提交,那么注释不 会保存到仓库中。
让我们试试看。
提交暂存的更改,然后重新检查状态。
$ git commit -m "Added a default value"
$ git status
你应该看到:
添加第二次更改
现在添加第二次更改到暂存区,然后执行 git status
。
$ git status
注意:我们使用当前目录(.)作为要添加的文件。这是一种 添加当前目录及其子目录下所有更改文件的习惯简写方式。 但因为它添加所有东东,所以在做 add .
前检查状态是一 个好主意,只是为了确定你没有添加不想要的文件。
我想你已经明白了 add .
这个技巧,但为了安全在余下的 教程中我们将继续直接添加文件。
你应该看到:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.rb
#