Information Technology Reference
In-Depth Information
$ git reset --hard abda
ectory contains all the files created in Recipes 3-3 and 3-4.
Caution
Recipe 3-5 clearly shows that the database stored in
.git/objects
and
the history of the repository are not the same thing. After the
$ git reset
command
some revisions are removed from the history but they are still available in the database.
The history of the repository is only a subset of all the information available in the data-
base. To obtain something from the database, you need a valid name.
How It Works
The history of the repository can be displayed as a list of revisions. We can use
$ git
log --pretty=oneline
or the alias
$ git l
. As you already know, every revi-
sion is identified by its unique name. To restore the working directory to one of the re-
visions you can use:
$ git reset --hard [REVISION]
The command performs the following two operations:
• It resets the state of the working directory to the specified revision, which
means that the contents of all the files and directories are restored to ex-
actly the same snapshot as was saved in the revision.
• It removes from the history all the revisions that were created after speci-
fied revision.
If you want to restore the original state of the repository, as it was before the
$ git
reset
command, you have to remember the name of the latest revision or alternat-
ively you can use reflog.
3-6. Restoring revisions with git checkout