Undo – Remove a commit and retain changes in the staging area
Of course, it is also possible to undo the commit, but keep the changes to the files in the index or the staging area so that you are ready to recreate the commit with, for example, some minor modifications.
Getting ready
We'll still use the example of the hello world repository. Make a fresh clone of the repository, or reset the master branch if you have already cloned one.
Create a fresh clone as follows:
$ git clone https://github.com/PacktPublishing/Git-Version-Control-Cookbook-Second-Edition_hello_world_cookbook.git $ cd Git-Version-Control-Cookbook-Second-Edition_hello_world_cookbook
We can reset the existing clone as follows:
$ git checkout master $ git reset --hard origin/master HEAD is now at 3061dc6 Adds Java version of 'hello world'
How to do it...
- Check whether we have any files in the modified state and check the log:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit...