Loading

UNDOING LOCAL CHANGES (BEFORE STAGING)

GOALS
  • Learn how to revert changes in the working directory

Checkout Master01

Make sure you are on the lastest commit in master before proceeding.

EXECUTE:
git checkout master

Change hello.rb02

Sometimes you have modified a file in your local working directory and you wish to just revert to what has already been committed. The checkout command will handle that.

Change hello.rb to have a bad comment.

FILE: hello.rb
# This is a bad comment.  We want to revert it.
name = ARGV.first || "World"

puts "Hello, #{name}!"

Check the Status03

First, check the status of the working directory.

EXECUTE:
git status
OUTPUT:
$ git status
# On branch master
# 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
#
no changes added to commit (use "git add" and/or "git commit -a")

We see that the hello.rb file has been modified, but hasn’t been staged yet.

Revert the changes in the working directory04

Use the checkout command to checkout the repository’s version of thehello.rb file.

EXECUTE:
git checkout hello.rb
git status
cat hello.rb
OUTPUT:
$ git checkout hello.rb
$ git status
# On branch master
nothing to commit (working directory clean)
$ cat hello.rb
# Default is "World"
name = ARGV.first || "World"

puts "Hello, #{name}!"

The status command shows us that there are no outstanding changes in the working directory. And the “bad comment” is no longer part of the file contents.

 

reference:http://gitimmersion.com/lab_14.html

posted @ 2012-04-26 11:21  .net's  阅读(460)  评论(0编辑  收藏  举报