git amend
| 28-Apr-2011 | Posted by Sonia Hamilton under Git |
A nice git option I stumbled upon today – amend.
Typical scenario – you’ve done a local check-in, then notice there’s a typo in your code comments. Fix up the typo, then use - – amend to re-check-in, without having to do a reset/revert. For example:
git add foo.file git ci -m "added the frob feature to the whiz-bang" ... notice and fix typo in foo.file ... git add foo.file git ci --amend
When you do the amend check-in, your editor will pop up, allowing you to re-edit the commit message if desired.
Obviously, if you’ve done a commit to a remote/public repository, amend has issues, similar to reset.
Also, I have entries like this in my .gitconfig, hence “git ci” rather than “git commit”.
[alias]
ci = commit
co = checkout
st = status
br = branch
Share This
Could run this at the command-line to get those aliases, maybe a minuscule amount less effort since don’t have to navigate to the right spot in the editor for pasting :-)
git config –global alias.co checkout
git config –global alias.ci commit
git config –global alias.st status
git config –global alias.br branch
oh, btw, that long dash, — , should appear/be typed as two dashes, but I think wordpress is trying to be too clever for its own good by converting it.
Hi Nick, yes WordPress and double dashes… I need to migrate to a blog that handles code better – any ideas? Or is it just the WordPress theme I wonder?
And the git config commands, yes I know :-) I have a series of scripts that keep all my machine settings all the same (.zshrc, git remotes, .screenrc, .vimrc and lots more…), and git config is run out of those scripts. And of course the scripts themselves are kept in git…
For example, my ~/bin/gitconfig script does:
PS and my .zshrc controls my prompt to show git info, for example:
I use https://github.com/olivierverdier/zsh-git-prompt for this.