Skip to content

Instantly share code, notes, and snippets.

@andyhasit
Created March 24, 2016 10:22
Show Gist options
  • Save andyhasit/3563d8aed1fd96662285 to your computer and use it in GitHub Desktop.
Save andyhasit/3563d8aed1fd96662285 to your computer and use it in GitHub Desktop.
"""
Script for creating past dated git commits. For the github green dots.
Usage:
>>> cheat 27/2 "my commit message"
will trigger:
>>>git commit -m "my commit message"
>>>git commit --amend --no-edit --date="Wed 27 Feb 21:56:23 2016 +0000"
Notes:
It uses the current datetime, at GMT.
Future:
Allow specifying of time (inc random)
Integrate with script to:
checkout first commit from repoA
cheat commit to repoB
increment date
repeat
(Thus letting you rebuild past projects and spanning commits one a day to get those green dots)
"""
import sys, subprocess, datetime
from dateutil.tz import tzlocal
def commit(msg):
"""
Will send:
git commit -m "your message"
"""
cmd = 'git commit -m "{0}"'.format(msg)
return subprocess.call(cmd)
def amend(date_str):
"""
Will send:
git commit --amend --no-edit --date="Wed 03 Feb 21:56:23 2016 +0000"
"""
now = datetime.datetime.now(tzlocal())
date_elements = date_str.split('/')
day = int(date_elements[0])
month = int(date_elements[1])
if len(date_elements) == 3:
year = int(date_elements[2])
if year < 100:
year = year + 2000
else:
year = now.year
new_date = datetime.datetime(year, month, day, now.hour, now.minute,
now.second)
new_date_str = new_date.strftime('%a %d %b %H:%M:%S %Y ') + now.strftime('%z')
cmd = 'git commit --amend --no-edit --date="{0}"'.format(new_date_str)
return subprocess.call(cmd)
if commit(sys.argv[2]) == 0:
amend(sys.argv[1])
else:
print 'Please pass a date and "message in quotes"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment