4 ms·
Woah I didn't know about git commit --amend, that's really cool!
by djcapelis 16y ago
Woah I didn't know about git commit --amend, that's really cool!
- steveklabnik 16y agoA 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.
- a-priori 16y agoAlso 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.
- avar 16y agoI 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.
- parenthesis 16y agogit 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.