3

I know that there is some kind of format that looks like master@{"1 day ago"} but I can't figure out how to use something to (in a friendly way) filter the output of git reflog to just the last X amount of time.

I tried git reflog --since="2 days ago" but it is definitely not giving me the results that I expect (as it produces 3 results all related to the current branch I'm on, and the first 36 entries in git reflog are from today).

Mainly I just need a list of all the (potentially orphaned) commits that I had a hand in creating from today. Because some shit went down, and I need to view all of the commits that have failed to get labeled with branch pointers, because I may or may not have rebased stuff wrong.

Meanwhile the only way to do it that I came up with is with a manual workflow something like this:

git reflog --date=relative | head -n 36 | cut -d' ' -f 1 | uniq | tr '\n' ' '

This produces a one line space separated set of commit hashes which should contain all the commits I touched today, and I found out through trial and error that if I just pass this over to my fancy git log --graph alias that it will helpfully inject them in the graph where they belong, and I can regain some sanity that way.

As with any reasonably recyclable git related capability that I discover, I like to try to generalize in a script or at least some StackOverflow breadcrumbs so I can better learn how to do it quickly the next time that this happens.

A handy alias that lets me run my typical git log --graph <lots of config> but with the addition of also viewing all orphaned commits inside that graph would be amazing. But I definitely want to limit that to only show me such commits from the last one day.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • I don't think you can do very much better than `git reflog --date=relative` or similar. The constant you have in your `head` (36) will depend on the number of reflog entries that fall into your desired time range, though. Processing the output in awk (looking for `seconds ago`, `minutes ago`, `hours ago`) seems like it might be easier, and then you could `print $1` to print just the hash, and even do the uniq-ifying in awk. – torek Sep 05 '17 at 23:15
  • I was hoping that since `git reflog` is supposed to take log-options that it would "just work" but the use of log options seems to change its filtering. `--all` didn't work either. I suppose I may settle for just dumping out the last 50 items and living with that. – Steven Lu Sep 05 '17 at 23:20
  • The problem is that `git reflog` is (in this case anyway) just a wrapper for `git log -g` aka `git log --walk-reflogs`, and that runs `git log` in a way that makes it not walk commit history. You need to run `git log` twice: once with these reflog commits selected so as to find them, and then a second time, in the normal history-walking way. – torek Sep 05 '17 at 23:33
  • Ah, yeah makes sense. I'd use the `--date=iso` on it then, at least that will be moderately safer to parse, though still not wonderful. – Steven Lu Sep 05 '17 at 23:34
  • That should work better soon: https://stackoverflow.com/a/45664200/6309 – VonC Sep 06 '17 at 05:35

1 Answers1

3

I confirm that, after re-compiling Git after commit 3ab01ac that I mention in "How to properly use git reflog --since=…?", reflog does work as expected:

git reflog --since="2 days ago" --all

It is part of the upcoming 2.14.2 release, which should be out very soon.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250