Skip to content

Instantly share code, notes, and snippets.

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"
Copy link

andreasnuesslein commented Mar 16, 2021

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

$ cat .gitconfig 
	name = me
	email = mymail

	diff = auto
	status = auto
	branch = auto

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


Copy link

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