Skip to content

Instantly share code, notes, and snippets.

@alexkuc
Last active June 18, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkuc/2d3b1e2c6d191306b9202107114cefb2 to your computer and use it in GitHub Desktop.
Save alexkuc/2d3b1e2c6d191306b9202107114cefb2 to your computer and use it in GitHub Desktop.
After doing a rebase, apply git filter-branch to keep original committer/author dates
# Very important assumption: you have commit messages with _unique_ subject lines ('%s')
# If not, you need to either modify my gist or "go back to the drawing" board…
# Use these to check if you have unique subject lines or not:
# (the numbers must be identical)
export BRANCH=master
export OLD_BRANCH=old_branch
git log --format="%s" "$BRANCH" | uniq | wc -l | xargs
git log --oneline "$BRANCH" | wc -l | xargs
# Before doing these changes, create a backup!
git filter-branch --force --env-filter 'GIT_COMMITTER_DATE=$(git log --format='%cd' --grep="$(git show --format='%s' --no-patch $GIT_COMMIT)" "$OLD_BRANCH")' "$BRANCH"
# Inspired by:
# https://codewithhugo.com/change-the-date-of-a-git-commit/
# https://stackoverflow.com/questions/30790645/how-to-make-a-git-rebase-and-keep-the-commit-timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment