Test Expired Reflog Entries
In this step, we'll learn about how Git manages the reflog and how entries can eventually expire. By default, Git keeps reflog entries for a certain period. Reachable entries (those pointed to by a branch or tag) are kept for 90 days, while unreachable entries (those not pointed to by anything) are kept for 30 days. After these periods, Git's garbage collection process might remove them.
While we can't simulate the passage of time in this lab to see entries expire naturally, we can manually trigger Git's garbage collection with a specific option to prune (remove) old reflog entries.
Important: Running this command will remove older reflog entries based on the configured expiration times. In a real-world scenario, you would typically not need to run this manually unless you have a specific reason to clean up old reflog entries.
First, ensure you are in the my-time-machine
directory:
cd ~/project/my-time-machine
Now, let's run the garbage collection command with the prune option for reflog entries. We'll set a very short expiration time for unreachable entries to demonstrate the effect.
git gc --prune=now --aggressive
This command tells Git to run garbage collection immediately (--prune=now
) and aggressively (--aggressive
) to clean up loose objects and prune unreachable reflog entries.
After running the command, let's check the reflog again:
git reflog
You might see that some older entries, especially if you had performed more operations before this lab, might be gone. In our simple repository with only two reflog entries, it's possible both are still present because they are relatively new and one is still reachable by HEAD
and master
. However, if you had a more complex history with unreachable commits, this command would prune them based on the expiration settings.
The key takeaway here is that the reflog is not permanent forever. Git cleans up old entries to save space. However, for typical development workflows, the default expiration times are usually sufficient to recover from most mistakes.
Understanding that reflog entries have an expiration helps you appreciate the importance of creating meaningful commits and branches to preserve important points in your project's history.