Skip to content

Commit 7a3896f

Browse files
committed
Add Include Or Exclude Remaining Patch Changes as a git til
1 parent 945b48f commit 7a3896f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-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-
_1035 TILs and counting..._
13+
_1036 TILs and counting..._
1414

1515
---
1616

@@ -242,6 +242,7 @@ _1035 TILs and counting..._
242242
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
243243
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)
244244
- [Include A Message With Your Stashed Changes](git/include-a-message-with-your-stashed-changes.md)
245+
- [Include Or Exclude Remaining Patch Changes](git/include-or-exclude-remaining-patch-changes.md)
245246
- [Include Some Stats In Your Git Log](git/include-some-stats-in-your-git-log.md)
246247
- [Intent To Add](git/intent-to-add.md)
247248
- [Interactively Unstage Changes](git/interactively-unstage-changes.md)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Include Or Exclude Remaining Patch Changes
2+
3+
I often use `git add --patch` as a way of interactively staging changes for a
4+
commit. Git walks me through each individual chunk of changes—which it calls
5+
_hunks_—so that I can include it or exclude it.
6+
7+
Sometimes, like when I'm working with a `yarn.lock` file, there are a ton of
8+
computer-generated changes to a file that I don't want to individually confirm.
9+
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.
10+
11+
A complementary scenario arises at times when working with a Rails `schema.rb`
12+
file. There are a bunch of Postgres client-specific changes that I don't want
13+
to commit. Once I get to the `schema.rb` file, I can hit `d` to _not_ stage
14+
this or all remaining hunks in the current file.
15+
16+
```
17+
a - stage this hunk and all later hunks in the file
18+
d - do not stage this hunk or any of the later hunks in the file
19+
```
20+
21+
This saves me from hitting `y` a dozen times to accept changes or hitting `n` a
22+
dozen times to decline changes.
23+
24+
See `man git-add` and look for the _Interactive mode_ section for more details.

0 commit comments

Comments
 (0)