Skip to content

Instantly share code, notes, and snippets.

@Sugavanas
Created November 13, 2021 23:45
Show Gist options
  • Save Sugavanas/bb7c60677d3d9ecc14de90050bc3351d to your computer and use it in GitHub Desktop.
Save Sugavanas/bb7c60677d3d9ecc14de90050bc3351d to your computer and use it in GitHub Desktop.
Git Alias Resign: Sign Old Commits and Keep commit date same as author date using rebase
echo "Don't execute this script directly. Edit it and copy the command you need.";
exit;
# Make sure you backup your .git folder (better the entire repository) before running this!
# USE AT YOUR OWN RISK!
# Tested with git version 2.33.1
# If on ubuntu, make sure to add the official repo from git to get the latest version.
# This will add a git alias
# Usage: git resign HASH
# In the interactive editor, make sure the correct commits are beign rebased.
# This command will resign all the commits until the HASH commit (not including)
git config --global alias.resign "rebase --exec 'GIT_COMMITTER_DATE=\"\$(git log -n 1 --format=%aD)\" git commit --amend --no-edit -n -S' -i"
# remove the -i if you like to live dangerously.
# Once done, before pushing, check the CommitDate value using
# git log --pretty="fuller"
# This will also run git log automatically
# git config --global alias.resign '!'"git rebase --exec 'GIT_COMMITTER_DATE=\"\$(git log -n 1 --format=%aD)\" git commit --amend --no-edit -n -S' -i \$1 && git log --pretty=\"fuller\" \$1..HEAD"
@bhanson-techempower
Copy link

For Git Bash on Windows, use double quotes if you execute the command manually:

git rebase --exec "GIT_COMMITTER_DATE=\"\$(git log -n 1 --format=%aD)\" git commit --amend --no-edit -n -S" -i YOUR_HASH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment