diff --git a/README.md b/README.md index fc6bb0e..47531e8 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). -_1035 TILs and counting..._ +_1036 TILs and counting..._ --- @@ -242,6 +242,7 @@ _1035 TILs and counting..._ - [Grep Over Commit Messages](git/grep-over-commit-messages.md) - [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md) - [Include A Message With Your Stashed Changes](git/include-a-message-with-your-stashed-changes.md) +- [Include Or Exclude Remaining Patch Changes](git/include-or-exclude-remaining-patch-changes.md) - [Include Some Stats In Your Git Log](git/include-some-stats-in-your-git-log.md) - [Intent To Add](git/intent-to-add.md) - [Interactively Unstage Changes](git/interactively-unstage-changes.md) diff --git a/git/include-or-exclude-remaining-patch-changes.md b/git/include-or-exclude-remaining-patch-changes.md new file mode 100644 index 0000000..1c9f241 --- /dev/null +++ b/git/include-or-exclude-remaining-patch-changes.md @@ -0,0 +1,24 @@ +# Include Or Exclude Remaining Patch Changes + +I often use `git add --patch` as a way of interactively staging changes for a +commit. Git walks me through each individual chunk of changes—which it calls +_hunks_—so that I can include it or exclude it. + +Sometimes, like when I'm working with a `yarn.lock` file, there are a ton of +computer-generated changes to a file that I don't want to individually confirm. +One of the options while interactively staging is to hit `a` which will stage the current hunk and all later hunks for the current file. + +A complementary scenario arises at times when working with a Rails `schema.rb` +file. There are a bunch of Postgres client-specific changes that I don't want +to commit. Once I get to the `schema.rb` file, I can hit `d` to _not_ stage +this or all remaining hunks in the current file. + +``` +a - stage this hunk and all later hunks in the file +d - do not stage this hunk or any of the later hunks in the file +``` + +This saves me from hitting `y` a dozen times to accept changes or hitting `n` a +dozen times to decline changes. + +See `man git-add` and look for the _Interactive mode_ section for more details.