How to do it...

First, we'll try to undo the latest commit in the repository as though it never happened:

  1. We'll make sure that our working directory is clean, no files are in the modified state, and nothing is added to the index:
$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 

nothing to commit, working directory clean 
  1. Also, check what is in our working tree:
$ ls 
HelloWorld.java Makefile        hello_world.c 
  1. If all works well, we'll check the log to see the history of the repository. We'll use the --oneline switch to limit the output:
$ git log --oneline 
3061dc6 Adds Java version of 'hello world' 
9c7532f Fixes compiler warnings 
5b5d692 Initial commit, K&R hello world 
  1. The most recent commit is the 3061dc6 ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.