Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:40:56+00:00 2026-06-17T10:40:56+00:00

I would like to commit a file with a custom date. So far I’ve

  • 0

I would like to commit a file with a custom date.

So far I’ve created a Commit object, but I don’t understand how to bind it to a repo.

from git import *
repo = Repo('path/to/repo')
comm = Commit(repo=repo, binsha=repo.head.commit.binsha, tree=repo.index.write_tree(), message='Test Message', committed_date=1357020000)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:40:57+00:00Added an answer on June 17, 2026 at 10:40 am

    Well I found the solution.

    I wasn’t aware, but I had to provide all the parameters otherwise the Commit object would throw a BadObject exception when trying to serialize it.

    from git import *
    from time import (time, altzone)
    import datetime
    from cStringIO import StringIO
    from gitdb import IStream
    
    repo = Repo('path/to/repo')
    
    message = 'Commit message'
    
    tree = repo.index.write_tree()
    parents = [ repo.head.commit ]
    
    # Committer and Author
    cr = repo.config_reader()
    committer = Actor.committer(cr)
    author = Actor.author(cr)
    
    # Custom Date
    time = int(datetime.date(2013, 1, 1).strftime('%s'))
    offset = altzone
    author_time, author_offset = time, offset
    committer_time, committer_offset = time, offset
    
    # UTF-8 Default
    conf_encoding = 'UTF-8'
    
    comm = Commit(repo, Commit.NULL_BIN_SHA, tree, 
          author, author_time, author_offset, 
          committer, committer_time, committer_offset,
          message, parents, conf_encoding)
    

    After creating the commit object, a proper SHA had to be placed, I didn’t have a clue how this was done, but a little bit of research in the guts of GitPython source code got me the answer.

    stream = StringIO()
    new_commit._serialize(stream)
    streamlen = stream.tell()
    stream.seek(0)
    
    istream = repo.odb.store(IStream(Commit.type, streamlen, stream))
    new_commit.binsha = istream.binsha
    

    Then set the commit as the HEAD commit

    repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several advanced scenarios I would like to solve, but I don't know
I would like to know as how to commit a file/folder to multiple folders
I would like to be able to do a cvs commit, but provide multi-line
I would like to update every single file's commit message within GitHub at certain
I would like to use a pre-commit hook in riak to validate the json
I'm writing a pre-commit hook, and would like to do a check on the
Seems like it would be better if you did commit followed by merge. I'm
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to take all the commit messages in my subversion log and
I have a layout file containing a listview that I would like to fill

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.