Created
May 15, 2016 23:54
-
-
Save pixelpicosean/15bc2f414776ff11112e4f481717a450 to your computer and use it in GitHub Desktop.
Change date of a commit http://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git#454750
This file contains hidden or 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 | |
| # date YYYY-mm-dd HH:MM:SS | |
| commit="$1" datecal="$2" | |
| temp_branch="temp-rebasing-branch" | |
| current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
| date_timestamp=$(gdate -d "$datecal" +%s) | |
| date_r=$(gdate -R -d "$datecal") | |
| 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