From 67ce95862314546a2d7272a9418655b16557c73b Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 4 Oct 2019 12:39:45 -0500 Subject: [PATCH] Add Quicker Commit Fixes With The Fixup Flag as a git til --- README.md | 3 +- ...uicker-commit-fixes-with-the-fixup-flag.md | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 git/quicker-commit-fixes-with-the-fixup-flag.md diff --git a/README.md b/README.md index e1a9856..bffd1a7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_847 TILs and counting..._ +_848 TILs and counting..._ --- @@ -212,6 +212,7 @@ _847 TILs and counting..._ - [List Untracked Files](git/list-untracked-files.md) - [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md) - [Pulling In Changes During An Interactive Rebase](git/pulling-in-changes-during-an-interactive-rebase.md) +- [Quicker Commit Fixes With The Fixup Flag](git/quicker-commit-fixes-with-the-fixup-flag.md) - [Rebase Commits With An Arbitrary Command](git/rebase-commits-with-an-arbitrary-command.md) - [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md) - [Rename A Remote](git/rename-a-remote.md) diff --git a/git/quicker-commit-fixes-with-the-fixup-flag.md b/git/quicker-commit-fixes-with-the-fixup-flag.md new file mode 100644 index 0000000..76e6b5d --- /dev/null +++ b/git/quicker-commit-fixes-with-the-fixup-flag.md @@ -0,0 +1,38 @@ +# Quicker Commit Fixes With The Fixup Flag + +Imagine you're working a feature branch and realize that the first commit you +made had a typo. You could just tack on another commit to fix the typo, but +that will add noise to your commit history. You can fix it up by making a +_fixup_ commit. + +1. Make your typo fix +2. Stage the fix +3. Find the SHA of the commit that you want to fix (e.g. `2ee53ad`) +4. Create a _fixup_ commit: `git commit --fixup 2ee53ad` + +This _fixup_ commit is tied to the original commit it is fixing. + +``` +❯ git log --pretty=oneline --abbrev-commit +b4258b6 (HEAD -> feature-branch) fixup! Add header +9c0d2b0 Different atomic change +2ee53ad Add header +8486b91 (master) Initial commit +``` + +To then apply the _fixup_, run `git rebase -i --autosquash master`. This will +present you with the following _interactive rebase_ screen: + +``` +pick 2ee53ad Add header +fixup b4258b6 fixup! Add header +pick 9c0d2b0 Different atomic change + +# Rebase 8486b91..b4258b6 onto 8486b91 (3 commands) +``` + +Because git knows that your _fixup_ commit is tied to `2ee53ad`, it +automatically moves it into place below that commit with the `fixup` command. + +Saving will apply and autosquash the fixup commit leaving you with a clean +commit history.