Last active
October 18, 2016 11:44
-
-
Save valtoni/7f4662c168c961bc6dee4961a899b0e8 to your computer and use it in GitHub Desktop.
Rewrite target author and commiter name/email/date with data from source commit
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/sh | |
| # Rewrite's the commit with data from source commit | |
| echo "WARNING: Your TARGET_COMMIT must have in your current branch." | |
| SOURCE_COMMIT=$1 | |
| TARGET_COMMIT=$2 | |
| SOURCE_COMMIT=$(git rev-parse $SOURCE_COMMIT) | |
| if [ $? -ne 0 ]; then | |
| echo "Your SOURCE_COMMIT ($SOURCE_COMMIT) doesn't exists." | |
| exit 1 | |
| fi | |
| TARGET_COMMIT=$(git rev-parse $TARGET_COMMIT) | |
| if [ $? -ne 0 ]; then | |
| echo "Your TARGET_COMMIT ($TARGET_COMMIT) doesn't exists." | |
| exit 1 | |
| fi | |
| # Warning: POTENTIALLY DESTRUCTIVE! | |
| rm -Rf .git/refs/original | |
| echo "Rewriting $SOURCE_COMMIT data to $TARGET_COMMIT" | |
| MESSAGE=$(git log --pretty="%s" -1 $SOURCE_COMMIT) | |
| AUTHOR_NAME=$(git log --pretty="%an" -1 $SOURCE_COMMIT) | |
| AUTHOR_EMAIL=$(git log --pretty="%ae" -1 $SOURCE_COMMIT) | |
| AUTHOR_DATE=$(git log --pretty="%ad" -1 $SOURCE_COMMIT) | |
| COMMITER_NAME=$(git log --pretty="%cn" -1 $SOURCE_COMMIT) | |
| COMMITER_EMAIL=$(git log --pretty="%ce" -1 $SOURCE_COMMIT) | |
| COMMITER_DATE=$(git log --pretty="%cd" -1 $SOURCE_COMMIT) | |
| git filter-branch --env-filter \ | |
| 'if [ "'"$TARGET_COMMIT"'" == "$GIT_COMMIT" ]; then | |
| export GIT_AUTHOR_NAME="'"$AUTHOR_NAME"'"; | |
| export GIT_AUTHOR_EMAIL="'"$AUTHOR_EMAIL"'"; | |
| export GIT_AUTHOR_DATE="'"$AUTHOR_DATE"'"; | |
| export GIT_COMMITTER_NAME="'"$COMMITER_NAME"'"; | |
| export GIT_COMMITTER_EMAIL="'"$COMMITER_EMAIL"'"; | |
| export GIT_COMMITTER_DATE="'"$COMMITER_DATE"'"; | |
| fi' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment