From 77cc07a908f8aacefbf78b47cab6ed7a31add412 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 7 Feb 2025 22:09:28 -0600 Subject: [PATCH] Add Reference Commits Earlier Than Reflog Remembers as a Git TIL --- README.md | 3 +- ...e-commits-earlier-than-reflog-remembers.md | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 git/reference-commits-earlier-than-reflog-remembers.md diff --git a/README.md b/README.md index 6b743e8..9ebe443 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1585 TILs and counting..._ +_1586 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -356,6 +356,7 @@ See some of the other learning resources I work on: - [Quicker Commit Fixes With The Fixup Flag](git/quicker-commit-fixes-with-the-fixup-flag.md) - [Rebase Commits With An Arbitrary Command](git/rebase-commits-with-an-arbitrary-command.md) - [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md) +- [Reference Commits Earlier Than Reflog Remembers](git/reference-commits-earlier-than-reflog-remembers.md) - [Remove Untracked Files From A Directory](git/remove-untracked-files-from-a-directory.md) - [Rename A Remote](git/rename-a-remote.md) - [Renaming A Branch](git/renaming-a-branch.md) diff --git a/git/reference-commits-earlier-than-reflog-remembers.md b/git/reference-commits-earlier-than-reflog-remembers.md new file mode 100644 index 0000000..9b3e5b0 --- /dev/null +++ b/git/reference-commits-earlier-than-reflog-remembers.md @@ -0,0 +1,34 @@ +# Reference Commits Earlier Than Reflog Remembers + +While preparing some stats for a recent blog post on [A Decade of +TILs](https://www.visualmode.dev/a-decade-of-tils), I ran into an issue +referencing chuncks of time further back than 2020. + +```bash +❯ git diff --diff-filter=A --name-only HEAD@{2016-02-06}..HEAD@{2017-02-06} -- "*.md" +warning: log for 'HEAD' only goes back to Sun, 20 Dec 2020 00:26:27 -0600 +warning: log for 'HEAD' only goes back to Sun, 20 Dec 2020 00:26:27 -0600 +``` + +This is because `HEAD@...` is a reference to the `reflog`. The `reflog` is a +local-only log of objects and activity in the repository. That date looks +suspiciously like the time that I got this specific machine and cloned the +repo. + +In order to access this information, I need a different approach of finding +references that bound these points in time. + +How about asking `rev-list` for the first commit it can find before the given +dates in 2017 and 2016 and then using those. + +```bash +❯ git rev-list -1 --before="2017-02-07 00:00" HEAD +17db6bc4468616786a8f597a10d252c24183d82e + +❯ git rev-list -1 --before="2016-02-07 00:00" HEAD +f1d3d1f796007662ff448d6ba0e3bbf38a2b858d + +❯ git diff --diff-filter=A --name-only f1d3d1f796007662ff448d6ba0e3bbf38a2b858d..17db6bc4468616786a8f597a10d252c24183d82e -- "*.md" + +# git outputs a bunch of files ... +```