ans February 2016

ignore git folder without removing from remote repo, and ignore new files

We have a git repository that has a folder in it we would like to untrack, so that:

  1. The folder is still in our remote directory, but any changes done locally are not shown when running "git status"
  2. Any new files that are automatically added to the folder are not tracked as well

Looking online we sort of came to the conclusion that if that folder wasn't added to the gitignore when it was created, then adding it to it afterwards simply won't stop tracking the folder. The folder is sort of a program generated folder, but we don't need it to be updated from the remote repo, but would like to still keep it there as it speeds up the process of some things. I've found a few solutions online and saw many people ran

git rm -r --cached <your directory>

which will un-track the folder, but also remove it from my remote repo, which is not what we want. I saw another solution that involved running

git update-index --assume-unchanged /dir/to/untrack

This will print out "Ignoring path dir", but if a new file is created in that folder, it shows up when running "git status". We also tried editing a file that was one directory below the one we set to untrack ( i.e. dir/to/untrack/dir2/changedThisFile.txt ) and that file still shows up when running "git status" too.

Any help or advice would be greatly appreciated.
Thanks!

Answers


David Deutsch February 2016

First you will need to "assume unchanged" for each individual file:

git ls-files -z /dir/to/untrack/ | xargs -0 git update-index --assume-unchanged

Then, add a .gitignore file to /dir/to/untrack/ that contains the following:

*
!/.gitignore

This should prevent any new changes/additions from being picked up.

Post Status

Asked in February 2016
Viewed 1,790 times
Voted 11
Answered 1 times

Search




Leave an answer