INNER CODE UNIT · Python
get_file_creation_date
DataTalksClub/datatalksclub.github.io · scripts/add_dateadded_from_git.py:50
def get_file_creation_date(file_path: Path) -> Optional[str]:
"""
Get the date when a file was first added to git.
Returns the date in YYYY-MM-DD format, or None if not found.
"""
project_root = get_project_root()
# Get relative path from project root
try:
rel_path = file_path.relative_to(project_root)
except ValueError:
# File is not under project root
return None
# Use git log to find when file was first added (--diff-filter=A means "Added")
cmd = [
'git',
'log',
'--format=%ai',