I have read very well-known link How to checkout in Git by date?
the command git rev-list
doesn't work for me - I am always getting the whole history of the commits, specified date time value seems to be ignored for my case.
Steps:
I am on my branch mynewbranch1
git log
presents these commits:
**commit 1250c4c2 (HEAD -> mynewbranch1)**
Author: john <>
Date: Tue May 10 11:27:45 2022 +0200
text1`
**commit ae99ff**
Author: john
Date: Mon May 9 17:22:37 2022 +0200
text2`
**commit 84e85**
Author: alex <>
Date: Mon May 9 16:13:47 2022 +0200
text3`
**commit 41b35**
Author: alex <>
Date: Mon May 8 16:11:31 2022 +0200
text4`
Now I execute following command:
git checkout $(git rev-list -n 1 --first-parent --before="2022-05-09 16:13:47" mynewbranch1)
I tried also with backticks:
git checkout `git rev-list -n 1 --first-parent --before="2022-05-09 16:13:47" mynewbranch1`
Now I want to create a new branch from it:
git checkout -b some_branch_from_above_date
But when I execute git log
on my new branch some_branch_from_above_date
I can again see all the commits! I would expect to have only the 3rd and 4th commit from the above list because only those are before the specified date: 2022-05-09 16:13:47
I must do this through the script so I need to checkout by date! I even tried, for testing purposes, with string syntax -900 days ago but I still get recent commits! Please help!
git checkout -b mynewbranch2 `git rev-list -n 1 --before="900 days ago" mynewbranch1`
UPDATE THANKS TO @LeGEC
Cause for this problem is because rev-list
filters only based on CommitDate. While my AuthorDate is different because I set dat in git commit
command explicitely with --date
option. This is seen with git log --format=fuller
command.
AuthorDate: Thu May 9 16:13:47 2022 +0200
CommitDate: Wed May 11 13:48:07 2022 +0200