Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I am working on a regression in the source code. I'd like to tell Git: "check out 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.

1 Answer

0 votes
by (50.2k points)

To keep your current changes the work can be stashed away, without committing it, with git stash. 

You would then use git stash pop to get it back. 

Or you can git commit it to a separate branch.

Check out it by date using rev-parse

checkout the commit with a specific date using rev-parse like this:

git checkout 'master@{masterip}'

Note:  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

This can be used if you don't want to use the reflog, is to use rev-list to get the commit at a particular point in time with:

git checkout `git rev-list -n 1 --first-parent --before="2019-07-27 13:37" master`

Browse Categories