In the previous examples, we assumed that the working tree was clean, that is, no tracked files are in the modified state. However, this is not always the case, and if a hard reset is done, 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.
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.
We can create the fresh clone as follows:
$ git clone https://github.com/dvaske/hello_world_cookbook.git $ cd hello_world_cookbook
We can reset the existing clone as follows:
$ cd hello_world_cookbook $ 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 condition, so we'll change
hello_world.c to the following: