Information Technology Reference
In-Depth Information
Reset the state of the repository to the first revision:
$ git reset --hard c4ac
Although the history printed with
$ git l
now contains only one revi-
sion—
c4ac a
—the other two revisions—
5c1ec
and
4580b
—are still available in
the database. You can restore them using their names or reflog. We did this in Recipe
3-8.
Right now the
$ git reflog
command prints the following output:
c4ac743 HEAD@{0}: reset: moving to c4ac
5c1ee9a HEAD@{1}: commit: c
45800dd HEAD@{2}: commit: b
c4ac743 HEAD@{3}: commit (initial): a
This means that the revisions
5c1ee9ac
and
45800ddb
are available under the
symbolic names
HEAD@{1}
and
HEAD@{2}
. We call this type of revisions
dangling
revisions
. Let's clear the reflog with:
$ git reflog expire --all --expire=now
After this command the reflog becomes empty. The
$ git
reflog command returns
empty results. It means that right now revisions
5c1ee9ac
and
45800ddb
are avail-
able only through their names. There are no symbolic names leading to revisions
b
and
c
. If that is the case, git can remove revisions from the database. This type of revisions
is called
unreachable revisions
.
Let's check, which objects stored in the
.git/objects
database are accessible
only by SHA-1 names:
$ git prune --dry-run
The output will contain—among the other things—two revisions:
45800ddc19fa325296437fdbd7cc7e5654619597 commit
5c1ee9a3f19f854c783fa87003cb1ecc5508971d commit
If you compare the output of
$ git l
, you will see that the output contains the
names of revisions
5c1ec
and
4580b
. In other words, if you now execute the com-