Reputation: 79467
How can I get a list of absolutely everything that can be reached that is ordered by date? Normal commits, stashes, dropped stashes, commits from deleted branches - everything that hasn't been vacuumed yet.
I'm asking because I need to find a particular commit (or stash) and I don't remember much except the date when it must have been added. Since I never run git gc
, I assume it should still be available somewhere.
I also need the to see the timestamp for each commit, because I will have to use that to narrow down the search to only commits/stashes that are around the date I have in mind.
Edit: In case it is not clear it is crucial that I search dangling commits and dropped stashes in addition to the normal ones. Questions like How can I make git log order based on author's timestamp? do not address that.
Upvotes: 5
Views: 1858
Reputation: 46765
Dangling commits only:
% git fsck --lost-found | awk '/^dangling commit/ {print $3}' \
| xargs -l1 sh -c $'time=$(git cat-file -p "$1" | awk \'/^committer/ {printf "%s", $(NF-1); exit}\'); printf "%s %s\n" "$1" "$(date -d@"$time" -Is)" ' _ \
| sort -rk2
Output:
c3c00af52dd3efcaaa76ac8a84e008ac0bd5db9e 2023-08-15T22:39:17+07:00
e77099f9ad2c5b1ccd3eb910848b0f35d598d00a 2023-08-15T22:38:50+07:00
983a95b7a12d38bdc2246006bb1e0face1ab6441 2023-08-14T13:53:56+07:00
To get a superset of commits including those reachable via the reflog, replace the first line with:
git fsck --unreachable | awk '/commit/ {print $3}' \
Upvotes: 5
Reputation: 332776
One thing to try is simply git reflog
or git reflog HEAD
(which are equivalent, the first is just a shorthand for the second).
The reflog tracks every commit that a particular ref points to; HEAD is the ref that points to what you have currently checked out, so if you ever had the commit in question checked out on this machine, and it hasn't yet been gc'd, it should show up in that list.
Upvotes: 4