What is git reflog expire, and how long are unreachable commits kept before they can be garbage collected?
Last updated
git reflog expireprunes old reflog entries (the log of where refs likeHEADhave pointed). Those entries are what keep abandoned commits safe fromgit gc.Defaults: entries for reachable commits expire after 90 days (
gc.reflogExpire). Entries for unreachable commits expire after 30 days (gc.reflogExpireUnreachable).So a lost commit is normally recoverable for about 30 days. Running
--expire-unreachable=now --allthengit gc --prune=nowdeletes it immediately.
- https://git-scm.com/docs/git-reflog/2.35.0
- https://blog.stackademic.com/understanding-git-reflog-your-safety-net-for-lost-commits-ac9b993661aa
- https://www.reddit.com/r/git/comments/unyp3a/what_happens_to_old_unreferenced_commits_after/
- https://www.kernel.org/pub/software/scm/git/docs/git-reflog.html
- https://dev.to/itxshakil/git-reflog-explained-recover-deleted-commits-lost-work-i4n
- https://adamj.eu/tech/2023/08/31/git-clear-unreachable-files/
- https://gist.github.com/boywijnmaalen/f052cd70fa6d924d58621b2e9c806adb
- https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog