# On branch master
# Changes to be committed:
# (use "git reset HEAD
..." to unstage) # # new file: README # modified: benchmarks.rb #
现 在两 个文 件 都已 暂 存 , 下次 提 交时 就会 一 并 记 录 到 仓库 。 假设 此 时, 你 想要 在
benchmarks.rb 里再加条注释,重新编辑存盘后,准备好提交。不过且慢,再运行 git status
看看:
$ vim benchmarks.rb
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD
..." to unstage) # # new file: README # modified: benchmarks.rb # # Changed but not
updated: # (use "git add ..." to update what will be committed) # # modified: benchmarks.rb #
怎么回事?benchmarks.rb 文件出现了两次!一次算未暂存,一次算已暂存,这怎么可能呢?
好吧,实际上 Git 只不过暂存了你运行 git add 命令时的版本,如果现在提交,那么提交的
是添加注释前的版本,而非当前工作目录中的版本。所以,运行了 git add 之后又作了修订
的文件,需要重新运行 git add 把最新版本重新暂存起来:
$ git add benchmarks.rb
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD
..." to unstage) # # new file: README # modified: benchmarks.rb #
忽略某些文件
一般我们总会有些文件无需纳入 Git 的管理,也不希望它们总出现在未跟踪文件列表。通
常都是些自动生成的文件,比如日志文件,或者编译过程中创建的临时文件等。我们可以
创建一个名为 .gitignore 的文件,列出要忽略的文件模式。来看一个实际的例子:
$ cat .gitignore
*.[oa]