mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Exclude A File From A Diff Output as a git til
This commit is contained in:
@@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||||
|
|
||||||
_954 TILs and counting..._
|
_955 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -219,6 +219,7 @@ _954 TILs and counting..._
|
|||||||
- [Diffing With Patience](git/diffing-with-patience.md)
|
- [Diffing With Patience](git/diffing-with-patience.md)
|
||||||
- [Dropping Commits With Git Rebase](git/dropping-commits-with-git-rebase.md)
|
- [Dropping Commits With Git Rebase](git/dropping-commits-with-git-rebase.md)
|
||||||
- [Dry Runs in Git](git/dry-runs-in-git.md)
|
- [Dry Runs in Git](git/dry-runs-in-git.md)
|
||||||
|
- [Exclude A File From A Diff Output](git/exclude-a-file-from-a-diff-output.md)
|
||||||
- [Excluding Files Locally](git/excluding-files-locally.md)
|
- [Excluding Files Locally](git/excluding-files-locally.md)
|
||||||
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
||||||
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
||||||
|
|||||||
29
git/exclude-a-file-from-a-diff-output.md
Normal file
29
git/exclude-a-file-from-a-diff-output.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Exclude A File From A Diff Output
|
||||||
|
|
||||||
|
When running `git diff <SHA>`, you'll see output for all files changed at that
|
||||||
|
commit. It's the same if you do a range of commits (e.g. `git diff
|
||||||
|
<SHA1>...<SHA2>`).
|
||||||
|
|
||||||
|
If you are looking for changes in a particular part of the tree, then other
|
||||||
|
changes will be a distraction. Some generated files, such as `yarn.lock`, can
|
||||||
|
create a lot of noise in the diff output.
|
||||||
|
|
||||||
|
You can get a more focused output by excluding certain files and paths. The
|
||||||
|
syntax for doing that, however, is a bit wonky.
|
||||||
|
|
||||||
|
To exclude a file, you have to add an argument formatted like
|
||||||
|
`':(exclude)<filename>`.
|
||||||
|
|
||||||
|
For instance, to exclude `yarn.lock`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git diff <SHA> -- . ':(exclude)yarn.lock'
|
||||||
|
```
|
||||||
|
|
||||||
|
or to exclude an entire directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git diff <SHA> -- . ':(exclude)spec/**'
|
||||||
|
```
|
||||||
|
|
||||||
|
[source](https://stackoverflow.com/questions/39931781/git-diff-stat-exclude-certain-files/39937070#39937070)
|
||||||
Reference in New Issue
Block a user