Commit 7ee60de7 authored by Kirill Smelkov's avatar Kirill Smelkov

git-amend: My program to mimic darcs amend-record with git

From 2010. Needs fixing with recent Git. And better be upstreamed

http://git.vger.kernel.narkive.com/SoHylGJE/rfc-patch-git-amend-darcs-like-amend-record-for-git
parent c888b752
#!/bin/sh -e
# git-amend: darcs like amend-record for git
# FIXME error handling
# TODO don't noise reflog
USAGE="<commit>"
SUBDIRECTORY_OK=Yes
. git-sh-setup
test "$#" = 1 || usage
commit=$1
# let's see if $commit is a valid one, and also transform it to sha1 for it not
# to be dependant on current HEAD
commit=$(git rev-parse "$commit")
# look out merges!
test -z "$(git log --merges ${commit}~..HEAD)" || \
die "E: can't amend commits behind merges"
# commit index, allowing empty commit just for being able to amend patch
# description
git commit --allow-empty -m "amend for $commit"
# save worktree/index state
work=$(git stash create)
test -n "$work" && git update-ref HEAD.amend-backup $work
# reset to clean work/index before going into rebase
git reset --hard HEAD
fixup_cmd=$(mktemp -t git-amend-fixupcmd.XXXXXX)
rest_cmd=$(mktemp -t git-amend-restcmd.XXXXXX)
trap 'rm -f "$fixup_cmd" "$rest_cmd"' 0
{
echo -ne "pick\t"; git log --pretty=oneline -1 ${commit}
echo -ne "fixup\t"; git log --pretty=oneline -1 ${HEAD}
} > "$fixup_cmd"
git log --pretty=oneline --reverse ${commit}..HEAD~ | awk '{print "pick\t" $0;}' \
> "$rest_cmd"
# now let's apply fixup part to commit
GIT_EDITOR="cat $fixup_cmd >" git rebase -i ${commit}~
# reword it
git commit -v --amend
# and apply rest
GIT_EDITOR="cat $rest_cmd >" git rebase -i HEAD
# TODO verify that we ended up at the same tree we started
# restore worktree/index state
test -n "$work" && git stash apply --index $work
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment