Technosorcery

Ramblings of Jacob Helwig.

Updated Git Rebase --interactive --autosquash Commit Preparation

| Comments

Previously I wrote about git rebase --interactive --autosquash, and showed a couple of helper aliases to aid in creating the specially formatted commit messages used by --autosquash.

In 1.7.4, Git gained built-in versions of these helpers (specifically in d71b8ba and 89ac122). It is now possible to use the commit command directly (or much more simple aliases) to create fixup and squash commits for use with --autosquash.

The built-in way to create a squash commit now looks like this:

Creating a squash commit using the `–squash` flag
1
2
3
4
5
6
7
8
9
10
11
12
13
% vim Foo.txt
% git commit -am 'Change all the "Bar"s to "Foo"s'
[topic-branch 2710f7c] Change all the "Bar"s to "Foo"s
 1 file changed, 2 insertions(+), 2 deletions(-)
% vim Bar.txt
% git commit -am 'Change all the "Foo"s to "Bar"s'
[topic-branch 27862f1] Change all the "Foo"s to "Bar"s
 1 file changed, 2 insertions(+), 2 deletions(-)
% vim Foo.txt
% git commit -a --squash HEAD~2
Waiting for Emacs...
[topic-branch 297de07] squash! Initial commit
 1 file changed, 2 insertions(+), 2 deletions(-)

Creating a fixup commit works just the same (substituting --squash with --fixup in the commit command), though Git won’t automatically pop open the editor to ask for additional information in the commit message (as this would be discarded by the interactive rebase). When using --squash the commit message options can also be used (Ex: -m, -c, -C, and -F).

Finally, here are the updated aliases for fixup, and squash made much more simple by these new flags to commit:

Updated ~/.gitconfig aliases
1
2
3
4
[alias]
    fixup = !sh -c 'git commit --fixup=$1' -
    squash = !sh -c 'git commit --squash=$1' -
    ri = rebase --interactive --autosquash

Update (2012-10-25): Fix aliases to have same usage pattern as previous ones.

Comments