Skip to content

Rewrite revision log

Kelson edited this page May 7, 2019 · 1 revision
#!/bin/bash                                                                                                                                              

# Pre-requisites:                                                                                                                                        
#                                                                                                                                                        
# * Run 'git checkout $original' where 'original is the commit message                                                                                   
#   which needs to be changed.                                                                                                                           
#                                                                                                                                                        
# * Run 'git commit --amend'                                                                                                                             
#                                                                                                                                                        
# Then run this script with 'new' being the newly created commit msg                                                                                     
# (post amend).                                                                                                                                          
#                                                                                                                                                        
# You need then to make 'git checkout branch' where 'branch' if the                                                                                      
# original branch you are working on (like 'releng')                                                                                                     

set -xe

err() { echo "Usage: $0 original new" 1>&2 && exit 1; }
original=$1
new=$2
test -z "$original" && err
test -z "$new" && err

git replace -d "$original" || echo "No original reference to delete"
git replace "$original" "$new"
git branch -a --contains="$original" | \
    perl -ne 's/^..//; s/^remotes\///; print unless / -> /' | \
    xargs git filter-branch -f "^$new"
git replace -d "$original"
git for-each-ref --format="%(refname)" refs/original/ | \
    xargs -n 1 git update-ref -d
Clone this wiki locally