AwesomeSam
AwesomeSam

Reputation: 163

I want to exclude files from tracking but save them in repo

I have a dir /data and my file main.py. I use this as a beta file and change this first, rather than deploying in production directly. Doing this manipulates the files in /data, and when I later commit it, it commits all the data/ files too, which of course I don't want to.

I tried adding the dir data/ in .gitignore, and then executing

git rm -rf --cached .
git add .

but when I try to commit, it shows I removed all the files in data/, which is exactly not I want.

What I wanted was: It just stops tracking the files, i.e. it will neither remove them, nor commit the changed files. How can I do this?

Upvotes: 0

Views: 123

Answers (1)

VonC
VonC

Reputation: 1324178

I found what I needed: --skip-worktree

You will have to apply skip-worktree to all elements inside that folder though.
See "Git Skip Worktree on All Tracked Files inside Directory and its Subdirectories"

As I explain in "Git - Difference Between 'assume-unchanged' and 'skip-worktree'"

Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked.
This does not work as expected, since Git may still check working tree files against the index when performing certain operations.

In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.

In your case though, that might work as a temporary workaround.
Don't forget a --no-skip-worktree to restore the folder index.

Upvotes: 1

Related Questions