Skip to content

Commit

Permalink
Enable Git's autosquash feature by default.
Browse files Browse the repository at this point in the history
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 ed6f009
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gitconfig
Expand Up @@ -21,5 +21,7 @@
template = ~/.gitmessage
[fetch]
prune = true
[rebase]
autosquash = true
[include]
path = ~/.gitconfig.local

5 comments on commit ed6f009

@iwz
Copy link
Contributor

@iwz iwz commented on ed6f009 May 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@laskaridis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for the commit message!

@georgebrock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bayleedev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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/

@bayleedev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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