Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shift date for multiple commits

Tags:

git

Accidentally I had set incorrect time and all my commits are with wrong time/date and I would like to shift commit times/dates (f.e +8 hours/ +10 days).

I have found solution for one commit but I was wondering whether it can be done for many commits in one branch. I have managed to figure out how to change date but I am lost with rebasing :

COMMITS=($(git rev-list $COM~..HEAD))
for COMMIT in "${COMMITS[@]}"
do
   COMMIT_DATE=$(git log $COMMIT -n1 --format=%aD)
   NEW_DATE=$(date -d "$COMMIT_DATE+30 days" -R)
   echo "I: $COMMIT FROM $COMMIT_DATE TO $NEW_DATE"
   GIT_COMMITTER_DATE="$NEW_DATE" GIT_AUTHOR_DATE="$NEW_DATE" git commit --amend --no-edit --date "NEW_DATE"
   ...... rebase command
done

How to correctly rebase?

like image 981
Kucera.Jan.CZ Avatar asked Aug 31 '26 14:08

Kucera.Jan.CZ


1 Answers

Thanks to Joe's hint I was able to write exactly what I wanted, therefore I will post it here for other viewers.

git filter-branch --env-filter '
COMMIT_DATE=$(git log $GIT_COMMIT -n1 --format=%aD);
NEW_DATE=$(date -d "$COMMIT_DATE+1 day" -R);
GIT_COMMITTER_DATE="$NEW_DATE"
export GIT_COMMITTER_DATE
GIT_AUTHOR_DATE="$NEW_DATE"
export GIT_AUTHOR_DATE
' SHA..HEAD
like image 163
Kucera.Jan.CZ Avatar answered Sep 03 '26 14:09

Kucera.Jan.CZ