Skip to content

How do I make commits with a specified date? #315

Closed
@avinassh

Description

@avinassh

I can't seem to find out how to make commit with specifying author_date and commit_date, but it did not really work:

import git
...
repo = git.Repo.init(repo_path)
repo.index.add(['some_file'])
repo.index.commit(message, authored_date=commit_date, committed_date=commit_date)

throws:

TypeError: commit() got an unexpected keyword argument 'authored_date'

Then I looked at the source and found out it does not really have parameters for commit datetime. (or am I missing something? Would you be interested in a PR which adds these parameters? I am interested to learn and make contribution 😄 )

So, I either I have to create a commit then change dates (using Commit object) or use git directly.

or set OS envs before commit call:

...
os.environ['GIT_AUTHOR_DATE'] = date_in_iso
os.environ['GIT_COMMITTER_DATE'] = date_in_iso
repo.index.commit(message)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions