mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Highlight Small Change On Single Line 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://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1639 TILs and counting..._
|
||||
_1640 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Get Started with Vimium](https://egghead.io/courses/get-started-with-vimium~3t5f7)
|
||||
@@ -349,6 +349,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [Grep For A Pattern On Another Branch](git/grep-for-a-pattern-on-another-branch.md)
|
||||
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
|
||||
- [Highlight Extra Whitespace In Diff Output](git/highlight-extra-whitespace-in-diff-output.md)
|
||||
- [Highlight Small Change On Single Line](git/highlight-small-change-on-single-line.md)
|
||||
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)
|
||||
- [Ignore Files Specific To Your Workflow](git/ignore-files-specific-to-your-workflow.md)
|
||||
- [Include A Message With Your Stashed Changes](git/include-a-message-with-your-stashed-changes.md)
|
||||
|
||||
44
git/highlight-small-change-on-single-line.md
Normal file
44
git/highlight-small-change-on-single-line.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Highlight Small Change On Single Line
|
||||
|
||||
Sometimes a change gets made on a single, long line of text in a Git tracked
|
||||
file. If it is a small, subtle change, then it can be hard to pick out when
|
||||
looking at the diff. A standard diff will show a green line of text stacked on
|
||||
a red line of text with no more granular information.
|
||||
|
||||
There are two ways we can improve the diff output in these situations.
|
||||
|
||||
The first is built-in to git. It is the `--word-diff` flag which will visually
|
||||
isolate the portions of the line that have changed.
|
||||
|
||||
```bash
|
||||
git diff --word-diff README.md
|
||||
```
|
||||
|
||||
Which will produce something like this:
|
||||
|
||||
```diff
|
||||
A collection of concise write-ups on small things I learn [-day to day-]{+day-to-day+} across a
|
||||
```
|
||||
|
||||
The outgoing part is wrapped in `[-...-]` and the incoming part is wrapped in
|
||||
`{+...+}`.
|
||||
|
||||
The second (and my preference) is to use
|
||||
[`delta`](https://github.com/dandavison/delta) as an external differ and pager
|
||||
for git.
|
||||
|
||||
```bash
|
||||
git -c core.pager=delta diff README.md
|
||||
```
|
||||
|
||||
I cannot visually demonstrate the difference in a standard code block. So I'll
|
||||
describe it. We see a red and green line stacked on each other, but with muted
|
||||
background colors. Then the specific characters that are different stand out
|
||||
because they are highlighted with brighter red and green. I [posted a visual
|
||||
here](https://bsky.app/profile/jbranchaud.bsky.social/post/3ln245orlxs2j).
|
||||
|
||||
`delta` can also be added as a standard part of your config like I demonstrate
|
||||
in [Better Diffs With Delta](git/better-diffs-with-delta.md).
|
||||
|
||||
h/t to [Dillon Hafer's post on
|
||||
`--word-diff`](https://til.hashrocket.com/posts/t994rwt3fg-finds-diffs-in-long-line)
|
||||
Reference in New Issue
Block a user