1#!/bin/sh 2# Give this a commit-ID specification. It will edit the associated comment. 3# Usual caveats apply; the edited one and all commits after will change IDs, 4# and pushing them to a repo with the old commits will wreak havoc. 5# Note also that this cavalierly overwrites refs/original. 6# 7# This script by Eric S. Raymond, March 2010, all rites perverted. It's based 8# on an idea by thiago from #git, but debugged and with a safety check. 9# It contains porcelain and porcelain byproducts. 10 11topdir=`git rev-parse --show-cdup` 12test -n "$topdir" && cd "$topdir" 13 14my_commit=`git rev-parse $1` || exit $? 15 16# Run a safety check before edits that could hose remotes. 17if test -n "`git branch -r --contains $mycommit`" 18then 19 echo -n "Commit has been pushed. Really edit? " 20 read yn 21 if test "$yn" != 'y' 22 then 23 exit 0 24 fi 25fi 26 27my_file=COMMIT_EDITMSG 28test -d .git && myfile=.git/COMMIT_EDITMSG 29 30# This effort to invoke the user's normal editor fails. 31# the problem is that anything the editor writes to stdout on the 32# controlling terminal becomes part of the commit message. So 33# the editor needs to actually run inside another window. 34#test -z "$GIT_EDITOR" && GIT_EDITOR=$EDITOR 35#test -z "$GIT_EDITOR" && GIT_EDITOR=vi 36#my_editor=$GIT_EDITOR 37 38# xterm -e vi should also work. 39my_editor=emacsclient 40 41export my_file my_commit my_editor 42 43exec git filter-branch -f --tag-name-filter cat --msg-filter ' 44if test "$GIT_COMMIT" = "$my_commit"; then 45 cat > $my_file; 46 $my_editor $my_file >/dev/null; 47 cat $my_file 48else 49 cat 50fi' "$1~.." 51 52# End 53