Skip to content

Instantly share code, notes, and snippets.

@obuchtala
Created September 21, 2017 14:22
Show Gist options
  • Select an option

  • Save obuchtala/5b37101632c9d3883d366be344dd4dc4 to your computer and use it in GitHub Desktop.

Select an option

Save obuchtala/5b37101632c9d3883d366be344dd4dc4 to your computer and use it in GitHub Desktop.
Rebasing a branch and retain the original committer information.
#!/usr/bin/env bash
# Fix branch commit data to be the same as author data
set -o errexit -o pipefail -o noglob -o noclobber -o nounset
IFS=$'\n\t'
parent=$1
# The command to execute for each commit
read -r -d '' command <<-'COMMAND' || true
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
COMMAND
# Rebase the current branch on top of the parent
git rebase -- "$parent"
# Rewrite all commits to use the author data
git filter-branch --force --env-filter "$command" -- "$parent..HEAD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment