ReynierPM ReynierPM - 23 days ago 5
Git Question

How to git checkout -b from two weeks ago or from an specific date?

I am trying to checkout and old version of my code from the

branch and I am doing as follow:

git checkout -b master_de1974 `git rev-list -n 1 --before="5 days ago" master`

Is that the right command? How I can be sure if I am getting the old code instead the new one?


You should refer to a specific commit to be sure you are at the exact "position", version of your code you expect.

To find the commit number, you can check on github/bitbucket or whatever is your remote repository. If you have not "UI repository", you can list your commit by using the git log command,, for example:

git log -n10

will display the 10 last commits that have been saved to the tree. Once you find your commit,you can create your new branch from here:

git checkout -b master_de1974 a9c146a09505837ec03b

Where a9c146a09505837ec03b is your commit number. Then you can be sure you are on the good date/commit, by typing again

git log -n1

It should show you the commit you choose to be back to.