Skip to content

Instantly share code, notes, and snippets.

@zwily
Created June 17, 2009 03:54
Show Gist options
  • Save zwily/131069 to your computer and use it in GitHub Desktop.
Save zwily/131069 to your computer and use it in GitHub Desktop.
[alias]
amend-message = "!bash -c ' \
c=$0; \
if [ $c == \"bash\" ]; then echo \"Usage: git amend-message <commit>\"; exit 1; fi; \
saved_head=$(git rev-parse HEAD); \
commit=$(git rev-parse $c); \
commits=$(git log --reverse --pretty=format:%H $commit..HEAD); \
echo \"Rewinding to $commit...\"; \
git reset --hard $commit; \
git commit --amend; \
for X in $commits; do \
echo \"Applying $X...\"; \
git cherry-pick $X >> /dev/null; \
if [ $? -ne 0 ]; then \
echo \" apply failed (is this a merge?), rolling back all changes\"; \
git reset --hard $saved_head; \
echo \" ** AMEND-MESSAGE FAILED, sorry\"; \
exit 1; \
fi; \
done; \
echo \"Done\"'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment