# rewrite_commit_date(commit, date_timestamp)## !! Commit has to be on the current branch, and only on the current branch !!## Usage example:## 1. Set commit 0c935403 date to now:## rewrite_commit_date 0c935403## 2. Set commit 0c935403 date to 1402221655:## rewrite_commit_date 0c935403 1402221655#rewrite_commit_date () {local commit="$1" date_timestamp="$2"local date temp_branch="temp-rebasing-branch"local current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ -z "$date_timestamp" ]]; thendate="$(date -R)"elsedate="$(date -R --date "@$date_timestamp")"fi
git checkout -b "$temp_branch" "$commit"GIT_COMMITTER_DATE="$date" git commit --amend --date "$date"git checkout "$current_branch"git rebase "$commit" --onto "$temp_branch"git branch -d "$temp_branch"}
pick c95a4b7 Modification 1pick 1bc0b44 Modification 2pick de19ad3 Modification 3pick c110e7e Modification 4pick 342256c Modification 5pick 5108205 Modification 6
# Rebase eadedca..5108205 onto eadedca (6 commands)## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit# f, fixup = like "squash", but discard this commit's log message# x, exec = run command (the rest of the line) using shell# d, drop = remove commit
#!/bin/bash
# change GIT_AUTHOR_DATE for commit at Thu Sep 14 13:39:41 2017 +0800# you can change the data_match to change all commits at any date, one day or one month# you can also do the same for GIT_COMMITTER_DATE
git filter-branch --force --env-filter '
date_match="^Thu, 14 Sep 2017 13+"
# GIT_AUTHOR_DATE will be @1505367581 +0800, Git internal formatauthor_data=$GIT_AUTHOR_DATE;author_data=${author_data#@}author_data=${author_data% +0800} # author_data is 1505367581
oneday=$((24*60*60))
# author_data_str will be "Thu, 14 Sep 2017 13:39:41 +0800", RFC2822 formatauthor_data_str=`date -R -d @$author_data`
if [[ $author_data_str =~ $date_match ]];then# remove one day from author_datanew_data_sec=$(($author_data-$oneday))# change to git internal format based on new_data_secnew_data="@$new_data_sec +0800"export GIT_AUTHOR_DATE="$new_data"fi' --tag-name-filter cat -- --branches --tags
commit <hash>gpg: Signature made Sun 25 Jul 2021 00:00:00 PM TZgpg: using TYPE key KEYgpg: Good signature from "Signer <email@domain.tld>"Author: Author <email@domain.tld>AuthorDate: Sat Jan 1 00:00:00 2000 +0000Commit: Author <email@domain.tld>CommitDate: Sat Jan 1 00:00:00 2000 +0000