Undo – Working with a dirty area
In the previous examples, we assumed that the working tree was clean, that is, no tracked files were in the modified state. However, this is not always the case, and if a hard reset is carried out, the changes to the modified files will be lost. Fortunately, Git provides a smart way to quickly put stuff away so that it can be retrieved later using the git stash
command.
Getting ready
Again, we'll 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.
We can create the 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'
We'll also need to have some files in the working...