Skip to content

Hide Files

Eric Bouchut edited this page Feb 19, 2020 · 2 revisions

Hide a File already Tracked by Git

You may sometimes need to ignore a file already tracked by git. Using the files .gitignore or .git/info/exclude won't work in this case but the following command may come in handy.

Hide a File

Run the following command to temporarily exclude a file from git tracking, pretending it never changed.
We hide this file from git.

git update-index --assume-unchanged FILE 

Unhide a File

Later on, if you need to commit changes to this file, simply use the opposite command to unhide this file from git:

git update-index --no-assume-unchanged FILE

Unhide all Hidden Files

If you want to unhide all hidden files:

git update-index --really-refresh

List Hidden Files

To list the files hidden from git, use this:

git ls-files -v | grep '^[a-z]' | cut -c3-

Aliases

The below aliases may come in handy if you intend to use the above commands on a regular basis or need an easier way to remember them without the syntax burden.

git config --global alias.hide       'update-index --assume-unchanged`
git config --global alias.unhide     'update-index --no-assume-unchanged`
git config --global alias.unhide-all 'update-index --really-refresh'
git config --global alias.hidden     '!git ls-files -v | grep '^[a-z]' | cut -c3-'