Java Reference
In-Depth Information
Now let's see what the log says for CowTask.java (in the src/cowshooter/ directory):
$ cd ~/Desktop/code/CowShooter/src/cowshooter
$ git log --oneline CowTask.java
44b39f3 Deleted variable declaration
e4ee198 Added zombie warning
aa58dfa First Commit
Your commit IDs, those magic numbers that are listed on each line, will be
different from mine. But let's use mine for this example.
So in this case, we want to go back to the last known good version of this file.
That means we want to skip back past commits 44b39f3 and e4ee198, and
check out this file at my commit ID aa58dfa, when life was happy:
$ git checkout aa58dfa CowTask.java
(Remember, your commit ID will be different.)
And silently but surely, CowTask.java reverts to its previous state, back before
you added the zombie text and before you deleted those variables.
Now the file has actually been changed, just as if you'd edited it by hand, so
be sure to commit this latest change with an appropriate message (perhaps
something like “That was a bad idea; back to the drawing board.”):
$ git commit -a -m 'That was a bad idea'
[master 0b6b051] That was a bad idea
1 file changed, 3 insertions(+), 2 deletions(-)
Our bad code hasn't been forgotten; just like a bad day at school or a rotten
quiz grade, it's part of history, as gitlog reveals:
$ git log --oneline CowTask.java
0b6b051 That was a bad idea
44b39f3 Deleted variable declaration
e4ee198 Added zombie warning
aa58dfa First Commit
And if you really wanted to, you could even go back to the bad version of the
code at commit 44b39f3 or commit e4ee198. That's part of Git's beauty: it
remembers everything, good and bad, and you can always go back in time.
You can use this same idea for multiple files that were involved in the same
commit—by specifying all the files you need instead of just the one. You can
even do it across the entire project—just don't specify any file to git checkout ,
and it will operate on the whole project repository.
 
 
Search WWH ::




Custom Search