diff --git a/README.md b/README.md index 73eb423..d802f80 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/git/auto-squash-those-fixup-commits.md b/git/auto-squash-those-fixup-commits.md new file mode 100644 index 0000000..7d38a4d --- /dev/null +++ b/git/auto-squash-those-fixup-commits.md @@ -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 `. + +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.