# Override an ignore for a specific file:
!file.js
# Override an ignore for the files in a directory:
!assets/*
# Override an ignore for the files in a directory and its subdirectories:
!assets/**
For example, there is parent rule to ignore eveything from .next/
directory,
now you want to keep .next/standalone/
directory only.
You need to first ignore everything from the parent folder first, i.e. .next/
.
Then, list your exclusion rules level by level.
# This .gitignore file is outside of .next/
# Ignore everything in .next/
.next/*
# Exclude standalone but I also need to exclude parent level folder.
!.next/
!.next/standalone
Sometimes there is a huge directory that I want to keep in git through git add -f
but I want git and vscode to ignore it due to performance reason.
The perfect example for this is the
output generated by the standalone mode of Next.js(e.g. .next/standalone/
).
I need to keep the standalone directory so that I can deploy on the webserver through git pull
.
# TODO: NOT WORKING, vscode still show 2K+ files changed.
# Clean up: Remove and push the deletion
git rm --cached -r .next/standalone/
git add .next/standalone/
git commit -m "Clean up first"
# From now on, ignore this directory because it is autogenerated.
git update-index --skip-worktree .next/standalone/
git update-index --assume-unchanged .next/standalone/
# To undo
git update-index --no-assume-unchanged .next/standalone/
git update-index --no-skip-worktree .next/standalone/