chore(diff): get better diffs in the terminal

This commit is contained in:
Michele Cereda
2024-05-02 02:03:01 +02:00
parent 9be6d5f1e1
commit d068c616f0
3 changed files with 18 additions and 0 deletions

View File

@@ -112,6 +112,7 @@ git log -p 'feature' --not 'master'
# Just show changes between two files.
git diff --no-index 'path/to/file/a' 'path/to/file/b'
git diff --no-index --word-diff --patience 'path/to/file/A' 'path/to/file/B'
# Stage changes for commit.
git add .
@@ -584,6 +585,7 @@ git diff --word-diff='porcelain'
# DO NOT consider them part of of the repository.
# This can be used to diff any two files.
git diff --no-index 'path/to/file/A' 'path/to/file/B'
git diff --no-index --word-diff --patience 'path/to/file/A' 'path/to/file/B'
```
Better word-aware diff:

12
snippets/diff.sh Normal file
View File

@@ -0,0 +1,12 @@
#!sh
# Sources:
# - https://stackoverflow.com/questions/8800578/how-to-colorize-diff-on-the-command-line
git diff --no-index 'file1' 'file2'
git diff --no-index --word-diff --patience 'file1' 'file2'
vimdiff 'file1' 'file2'
diff 'file1' 'file2'
diff -y -W 'width' 'file1' 'file2'

4
snippets/view.sh Normal file
View File

@@ -0,0 +1,4 @@
#!sh
# Just `vim` but read-only.
view 'file'