From 81095b1e4716c0ea9c429f680f021ce2783b7bef Mon Sep 17 00:00:00 2001 From: Dejavu Moe Date: Sun, 14 May 2023 16:05:35 +0800 Subject: rename batch-rewrite-git-commit-logs.sh --- git/batch-rewrite-git-commit-logs.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 git/batch-rewrite-git-commit-logs.sh (limited to 'git/batch-rewrite-git-commit-logs.sh') diff --git a/git/batch-rewrite-git-commit-logs.sh b/git/batch-rewrite-git-commit-logs.sh new file mode 100644 index 0000000..583bca1 --- /dev/null +++ b/git/batch-rewrite-git-commit-logs.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# set the committed user information to be replaced +old_user="old userName" +old_email="old@mail.com" +new_user="new userName" +new_email="new@mail.com" + +# get global gpg signing key +signingkey=$(git config --global user.signingkey) + +# rewrite the git commit history and sign new commits +git filter-branch --env-filter " + if [ \"\$GIT_AUTHOR_EMAIL\" = \"$old_email\" ] && [ \"\$GIT_AUTHOR_NAME\" = \"$old_user\" ]; then + export GIT_AUTHOR_EMAIL=\"$new_email\" + export GIT_AUTHOR_NAME=\"$new_user\" + export GIT_COMMITTER_EMAIL=\"$new_email\" + export GIT_COMMITTER_NAME=\"$new_user\" + export GIT_COMMITTER_SIGNINGKEY=\"$signingkey\" + export GIT_AUTHOR_SIGNINGKEY=\"$signingkey\" + fi +" --tag-name-filter cat --commit-filter 'git commit-tree -S "$@"' -- --branches --tags \ No newline at end of file -- cgit v1.2.3-54-g00ecf