Skip to content

Commit 190d178

Browse files
committed
Add Auto-Squash Those Fixup Commits as a git til
1 parent b1b9d05 commit 190d178

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1016 TILs and counting..._
13+
_1017 TILs and counting..._
1414

1515
---
1616

@@ -213,6 +213,7 @@ _1016 TILs and counting..._
213213

214214
- [Accessing a Lost Commit](git/accessing-a-lost-commit.md)
215215
- [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md)
216+
- [Auto-Squash Those Fixup Commits](git/auto-squash-those-fixup-commits.md)
216217
- [Caching Credentials](git/caching-credentials.md)
217218
- [Change The Start Point Of A Branch](git/change-the-start-point-of-a-branch.md)
218219
- [Checking Commit Ancestry](git/checking-commit-ancestry.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Auto-Squash Those Fixup Commits
2+
3+
As a fan of [atomic commits](https://dev.to/jbranchaud/atomic-commits-4hk2), I
4+
sometimes find myself with some changes that are ready to stage that belong on
5+
an earlier commit. If it is the immediately previous, I'll do an `--amend`. For
6+
anything further back than that, I've come to love the use of `git commit
7+
--fixup <SHA>`.
8+
9+
Once one or more _fixup_ commits are on the current branch, they'll need to be
10+
_squashed_ into the commits for which they've been targeted. This calls for a
11+
`git rebase`.
12+
13+
Git knows how to squash fixup commits into the correct place, but you have to
14+
tell it to do so automatically. You can do that one of two ways.
15+
16+
You can either include the `--autosquash` flag each time you rebase:
17+
18+
```bash
19+
$ git rebase -i --autosquash
20+
```
21+
22+
Or you can tell Git to always autosquash in your `~/.gitconfig`:
23+
24+
```
25+
[rebase]
26+
autoSquash = true
27+
```
28+
29+
See the section on `--autosquash` in `man git-rebase` for more details.

0 commit comments

Comments
 (0)