Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Alias: ignore package-lock.json and yarn.lock in git diff

Don't want to see package-lock.json and yarn.lock in your git diff? Here are two nifty aliases that hide these files from your diff.

alias gd="git diff -- :!package-lock.json :!yarn.lock"
alias gds="git diff --staged -- :!package-lock.json :!yarn.lock"
@andreasnuesslein

This comment has been minimized.

Copy link

@andreasnuesslein andreasnuesslein commented Mar 16, 2021

just btw, you can add such aliases directly to your ~/.gitconfig, like so:

$ cat .gitconfig 
[user]
	name = me
	email = mymail

[color]
	diff = auto
	status = auto
	branch = auto

[alias]
	rs = restore --staged
	co = checkout
	ci = commit
	cp = cherry-pick
	st = status
	d = diff :!package-lock.json
	dc = diff --cached :!package-lock.json


...

@eliasnorrby

This comment has been minimized.

Copy link

@eliasnorrby eliasnorrby commented May 4, 2021

You can also add entries to a .gitattributes file within your repo to exclude them from any diff output. This has the benefit of working every time git produces a diff, and not just when you use your alias.

package-lock.json -diff
yarn.lock -diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment