Last active
June 18, 2020 17:44
-
-
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
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
# 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