在处理之前确认你在 master 中的最新提交上。

    更改 hello.rb 让其具有错误的注释。

    1. # This is a bad comment. We want to revert it.
    2. name = ARGV.first || "World"
    3. puts "Hello, #{name}!"
    1. # On branch master
    2. # Changes not staged for commit:
    3. # (use "git checkout -- <file>..." to discard changes in working directory)
    4. #
    5. # modified: hello.rb
    6. #
    7. no changes added to commit (use "git add" and/or "git commit -a")

    我们看到 hello.rb 已被修改,但还没有暂存。

    1. # On branch master
    2. nothing to commit (working directory clean)
    3. $ cat hello.rb
    4. # Default is "World"
    5. name = ARGV.first || "World"
    6. puts "Hello, #{name}!"

    命令显示在工作目录中没有未完成的更改。而且“错 误的注释”也不再成为文件内容的一部分。