Re:Git your act together
by djcapelis on Monday August 23, 2010 @02:33PM
(#1627565)
Woah I didn't know about git commit --amend, that's really cool!
[ Parent
| on HN ]
Also for more severe rewriting of the history check out "git rebase -i <base commit>". You'll be shown a list of commits between the base commit and the HEAD in your editor. From here you can rearrange and delete commits, and mark them for editing and squashing.
I use this all the time for cleaning up topic branches before I push them out.
Re:Git your act together
by parenthesis on Monday August 23, 2010 @04:35PM
(#1627969)
git commit --amend is also useful for when you immediately realise that you aren't happy with the commit message (it has a typo in it, or you forgot to mention something), as you can use it without git add -ing anything, just to edit the message.
Re:Git your act together
by steveklabnik on Monday August 23, 2010 @02:50PM
(#1627622)
A quick note about amend, if you git push before you amend your commit, when you try to push the amended commit, you'll get an error about non-fast-forward references. If you're sure that nobody has grabbed your commit since you've pushed it, you can just git push -f, and it'll replace your original commit with the amended one.
I sometimes use --amend, but it's good to get yourself into the habit of just making a new commit, then squashing it with git rebase -i.
I use magit.el for Emacs which makes this really easy, and if you screw up getting your data back from the reflog is a lot easier than if you just had a bunch of --amend fixups.