Last active
August 29, 2015 14:27
-
-
Save littlecho/643137cea4096a2eaee6 to your computer and use it in GitHub Desktop.
Script for shifting days for timestamp of commit in Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# commit | |
# number of days before for shifting to | |
commit="$1" | |
daysago=$2 | |
temp_branch="temp-rebasing-branch" | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
original_timestamp="$(git show -s --format=%ct "$commit")" #unix timestamp here | |
ori_readable=$(date -d "@$original_timestamp") #print this out if you need it | |
new_timestamp=$(( $original_timestamp - 86400 * $daysago)) #shift n days for original timestamp | |
date_timestamp=$(date -d "@$new_timestamp") #convert calculated timestamp to readable timestamp | |
date_r=$(date -R -d "$date_timestamp") #convert timestamp to git compatible timestamp | |
if [[ -z "$commit" ]]; then | |
exit 0 | |
fi | |
git checkout -b "$temp_branch" "$commit" | |
GIT_COMMITTER_DATE="$date_timestamp" GIT_AUTHOR_DATE="$date_timestamp" git commit --amend --no-edit --date "$date_r" | |
git checkout "$current_branch" | |
git rebase --autostash --committer-date-is-author-date "$commit" --onto "$temp_branch" | |
git branch -d "$temp_branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment