Skip to content

Instantly share code, notes, and snippets.

@dfdemar
Last active October 14, 2024 15:54
Show Gist options
  • Save dfdemar/d33f9fb4dabe2d9652ef72d2a539e9e7 to your computer and use it in GitHub Desktop.
Save dfdemar/d33f9fb4dabe2d9652ef72d2a539e9e7 to your computer and use it in GitHub Desktop.
Sets the committer date to the author date for every commit in a git branch
#!/bin/bash
# Get the current branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Get the first commit on the current branch that is not on the main branch
FIRST_COMMIT=$(git rev-list main..${BRANCH} --reverse | head -1)
# Change the committer date to the author date for all commits from the first commit to the current branch
git filter-branch -f --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' \
--commit-filter 'git commit-tree -S "$@";' ${FIRST_COMMIT}^...${BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment