Skip to content

Instantly share code, notes, and snippets.

@edubkendo
Forked from dpwright/.gitconfig
Created June 26, 2012 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edubkendo/2993724 to your computer and use it in GitHub Desktop.
Save edubkendo/2993724 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"
@edubkendo
Copy link
Author

via @dpwright comment :

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.

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