Created
June 3, 2019 18:32
-
-
Save dceoy/eae40cf0b365fbae4f19fe89b74bd995 to your computer and use it in GitHub Desktop.
[Shell] Rewind days at the latest commit of Git logs
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
#!/usr/bin/env bash | |
# | |
# Usage: ./git_rewind_days.sh <int> | |
set -eux | |
DAYS_TO_REWIND="${1}" | |
COMMIT_DATE=$(git log -1 | sed -ne 's/^Date: \+//p') | |
REWIDED_DATE=$(date -d "${COMMIT_DATE% *} - ${DAYS_TO_REWIND} days" | awk '{print $1" "$2" "$3" "$4" "$6}')" ${COMMIT_DATE##* }" | |
git rebase HEAD^ | |
git commit --amend --no-edit --date "${REWIDED_DATE}" | |
git rebase HEAD^ --committer-date-is-author-date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment