I’m trying to use git filter-repo to remove all commits before a certain date while preserving all files that exist in the most recent commit. I’ve used the following command:
git filter-repo --commit-callback '
import datetime
import time
timestamp_str, tz_str = commit.author_date.decode("utf-8").split()
timestamp = int(timestamp_str)
commit_date = datetime.datetime.fromtimestamp(timestamp)
if commit_date < datetime.datetime(2024, 1, 11):
commit.skip()
'
This successfully removes commits before January 11, 2024. However, after running this command, I’ve noticed that many files have disappeared from my repository. These files should still be present as they exist in the latest commit.
How can I modify this command or approach to achieve the following:
- Remove all commits before January 11, 2024
- Preserve all files that exist in the most recent commit, regardless of when they were last modified
I want to clean up the commit history without losing any current files. Any help or guidance would be greatly appreciated.
shawVI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.