Permalink
Browse files

Enable Git's autosquash feature by default.

Autosquash makes it quicker and easier to squash or fixup commits during an
interactive rebase. It can be enabled for each rebase using `git rebase -i
--autosquash`, but it's easier to turn it on by default.

Say I have this history:

    $ git log --oneline
    aaa1111 A first commit
    bbb2222 A second commit
    ccc3333 A third commit

I make another change that I already know should be squashed into "A
second commit". I can do this:

    $ git add .
    $ git commit --squash bbb2222
    [my-branch ddd4444] squash! A second commit

Then when I rebase:

    $ git rebase -i origin/my-branch

The interactive rebase list will be set up ready to squash:

    pick aaa1111 A first commit
    pick bbb2222 A second commit
    squash ddd4444 squash! A second commit
    pick ccc3333 A third commit

Since it's unlikely that anyone will be writing a commit message that begins
`squash!` or `fixup!` when they don't want this behaviour, and the user
still has a chance to review what's going to happen with the rebase, it's
safe to have it always turned on.
  • Loading branch information...
georgebrock committed May 3, 2015
1 parent 5724d12 commit ed6f00931a075a56305bdc391e483cb8f0b35ed3
Showing with 2 additions and 0 deletions.
  1. +2 −0 gitconfig
@@ -21,5 +21,7 @@
template = ~/.gitmessage
[fetch]
prune = true
[rebase]
autosquash = true
[include]
path = ~/.gitconfig.local

5 comments on commit ed6f009

@iwz

This comment has been minimized.

Copy link
Contributor

iwz replied May 12, 2015

whoa this is awesome! thanks for the nice writeup in the commit message

@laskaridis

This comment has been minimized.

Copy link

laskaridis replied Jun 2, 2015

👍 for the commit message!

@georgebrock

This comment has been minimized.

Copy link
Member

georgebrock replied Jul 12, 2015

I've seen this commit getting passed around and tweeted quite a bit, so I expanded the message into a more detailed blog post: https://robots.thoughtbot.com/autosquashing-git-commits

@blainesch

This comment has been minimized.

Copy link
Contributor

blainesch replied Jul 12, 2015

@georgebrock is there an easy way to make a fixup commit? I've seen one described in a blogpost, let me see if I can dig it up.

Yup, here we go...
https://technosorcery.net/blog/2010/02/07/fun-with-the-upcoming-1-7-release-of-git-rebase---interactive---autosquash/

@blainesch

This comment has been minimized.

Copy link
Contributor

blainesch replied Jul 12, 2015

@georgebrock oh it looks like git has this built in now. Maybe I missed this... disregard [:

I should have read your article first!

Please sign in to comment.