Skip to content

Instantly share code, notes, and snippets.

@dpwright
Created June 26, 2012 06:14
Show Gist options
  • Save dpwright/2993701 to your computer and use it in GitHub Desktop.
Save dpwright/2993701 to your computer and use it in GitHub Desktop.
Git alias to amend a specific commit earlier in the tree
amend-commit = "!f() { START=`(git symbolic-ref -q HEAD || git rev-parse HEAD) | cut -d"/" -f 3`; git checkout -q $1 && git commit --amend && git rebase --onto HEAD $1 $START; }; f"
@dpwright
Copy link
Author

Written following a brief discussion in #git on freenode (based on a suggestion by constant and suggested implementation by frogonwheels). This alias makes amending earlier commit messages easier, but is a bit dangerous as if there are branches based on the earlier commit other than that which is currently checked out, they will need to be rebased manually onto the new, amended commit.

Works even if you're in a detached HEAD state, but as above, any branches will need to be manually rebased.

@Ajedi32
Copy link

Ajedi32 commented May 23, 2013

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment