Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ALL Commit Dates in GIT

Tags:

git

Is there anyway I can change all of the commit dates in GIT by subtracting, let's say a week, from all dates.

Like, instead of showing "On date Thu, Sept 10 2012 USER committed..." I would like it to say "On date Mon, Sept 3 2012 USER committed..."

This is for only one GIT repository. Thanks!

like image 846
narcis Avatar asked Oct 15 '25 14:10

narcis


1 Answers

Yes, you can do this with git filter-branch. Note however that this will impact all the hashes, too, all commits would be recreated and the repo history rewritten. So, it can be dangerous.

You'd need to use git filter-branch with an env filter that sets GIT_AUTHOR_DATE and GIT_COMMITTER_DATE variables. In github there is example script to change author info for all commits - it is similar stuff, you'd just need to use the variables I mentioned instead, as well as implement a logic that decides based on a given date what was the date a week ago.

Final warning: if anybody has already worked with that repo, things can get messy. From the github page:

This action is destructive to your repo's history. It's best to do this on a clone, just in case. Also beware that this should not be performed on a repo that has been shared with others. Use at your own risk.

like image 142
eis Avatar answered Oct 18 '25 03:10

eis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!