The .git/logs/HEAD File
The .git/logs/HEAD file is a plain-text log located within the administrative directory of a git repository. It is the primary storage mechanism for the reflog of the head pointer. This file tracks every instance where the active reference of the repository changes, whether through a git-commit, git-checkout, git-reset, or git-merge. Unlike the standard commit history, which is shared during network operations, the data in .git/logs/HEAD is strictly local to the individual workstation.
According to the official Git Documentation, these logs are used to prevent the garbage-collection of commits that are no longer reachable by a named branch or tag. Each line in the file follows a specific format: the previous sha-1 hash, the new sha-1 hash, the committer's name and email, a unix-timestamp, and a descriptive message about the action performed. This granular history makes the file indispensable for data-recovery when a developer accidentally loses a commit.
For those exploring git-internals, understanding this file reveals how the git-reflog command retrieves its information. More detailed technical specifications on reference logs can be found in the Pro Git Book. This log ensures that even in complex rebasing or resetting scenarios, the state of the workspace can be restored to any previous point in time.