mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Auto-Squash Those Fixup Commits as a git til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1016 TILs and counting..._
|
||||
_1017 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -213,6 +213,7 @@ _1016 TILs and counting..._
|
||||
|
||||
- [Accessing a Lost Commit](git/accessing-a-lost-commit.md)
|
||||
- [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md)
|
||||
- [Auto-Squash Those Fixup Commits](git/auto-squash-those-fixup-commits.md)
|
||||
- [Caching Credentials](git/caching-credentials.md)
|
||||
- [Change The Start Point Of A Branch](git/change-the-start-point-of-a-branch.md)
|
||||
- [Checking Commit Ancestry](git/checking-commit-ancestry.md)
|
||||
|
||||
29
git/auto-squash-those-fixup-commits.md
Normal file
29
git/auto-squash-those-fixup-commits.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Auto-Squash Those Fixup Commits
|
||||
|
||||
As a fan of [atomic commits](https://dev.to/jbranchaud/atomic-commits-4hk2), I
|
||||
sometimes find myself with some changes that are ready to stage that belong on
|
||||
an earlier commit. If it is the immediately previous, I'll do an `--amend`. For
|
||||
anything further back than that, I've come to love the use of `git commit
|
||||
--fixup <SHA>`.
|
||||
|
||||
Once one or more _fixup_ commits are on the current branch, they'll need to be
|
||||
_squashed_ into the commits for which they've been targeted. This calls for a
|
||||
`git rebase`.
|
||||
|
||||
Git knows how to squash fixup commits into the correct place, but you have to
|
||||
tell it to do so automatically. You can do that one of two ways.
|
||||
|
||||
You can either include the `--autosquash` flag each time you rebase:
|
||||
|
||||
```bash
|
||||
$ git rebase -i --autosquash
|
||||
```
|
||||
|
||||
Or you can tell Git to always autosquash in your `~/.gitconfig`:
|
||||
|
||||
```
|
||||
[rebase]
|
||||
autoSquash = true
|
||||
```
|
||||
|
||||
See the section on `--autosquash` in `man git-rebase` for more details.
|
||||
Reference in New Issue
Block a user