I am working on a regression in the source code. I’d like to tell Git: “checkout the source based on a parameterized date/time”. Is this possible?
I also have staged changes in my current view that I don’t want to lose. Ideally, I would like to toggle back and forth between the current source, and some version I’m interested in based on a previous date.
To keep your current changes
You can keep your work stashed away, without commiting it, with
git stash. Youwould than use
git stash popto get it back. Or you can (as carleeto said)git commitit to a separate branch.Checkout by date using rev-parse
You can checkout a commit by a specific date using
rev-parselike this:More details on the available options can be found in the
git-rev-parse.As noted in the comments this method uses the reflog to find the commit in your history. By default these entries expire after 90 days. Although the syntax for using the reflog is less verbose you can only go back 90 days.
Checkout out by date using rev-list
The other option, which doesn’t use the reflog, is to use
rev-listto get the commit at a particular point in time with:Note the –first-parent if you want only your history and not versions brought in by a merge. That’s what you usually want.