Skip to content

Instantly share code, notes, and snippets.

@dceoy
Created June 3, 2019 18:32
Show Gist options
  • Save dceoy/eae40cf0b365fbae4f19fe89b74bd995 to your computer and use it in GitHub Desktop.
Save dceoy/eae40cf0b365fbae4f19fe89b74bd995 to your computer and use it in GitHub Desktop.
[Shell] Rewind days at the latest commit of Git logs
#!/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