git amend

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”.

        ci = commit
        co = checkout
        st = status
        br = branch

Share This


4 Responses to git amend

  1. 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 checkout
    git config –global commit
    git config –global status
    git config –global branch

  2. 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.

  3. 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:

    # vim:filetype=sh
    [ -f "$HOME"/.gitconfig ] && rm "$HOME"/.gitconfig
    git config --global "Sonia Hamilton"
    git config --global ""
    # color
    git config --global color.ui "auto"
    git config --global color.branch.current   "green"
    git config --global color.branch.local     "yellow"
    git config --global color.branch.remote    "red"
    git config --global color.diff.meta        "yellow bold"
    git config --global color.diff.frag        "magenta bold"
    git config --global color.diff.old         "red bold"
    git config --global         "green bold"
    # aliases
    git config --global "commit"
    git config --global "checkout"
    git config --global "status"
    git config --global "branch"
    git config --global "show-branch"
    git config --global "show-branch --sha1-name"
    git config --global "log --graph --pretty=oneline --abbrev-commit"
    git config --global "clean -x -d -f"
    git config --global alias.dt "difftool"
    git config --global alias.difft "difftool"
    # misc
    git config --global github.user soniah
    git config --global github.token secret.squirrel.stuff
    git config --global diff.tool vimdiff
    git config --global difftool.prompt false
  4. PS and my .zshrc controls my prompt to show git info, for example:

    sonia@uva ~/dotfiles j 1 (master‣1)

    I use for this.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>