Ignoring an already checked-in directory's contents?

Viewed 82327

I have a git repository that's used only to hold graphics and sound files used in several projects. They are all in one directory without sub-directories. Now I just created a script to copy these assets over from another, structured directory, with several levels of sub-directories.

Now I only want the (source) hierarchical file structure to be tracked by git, and the (target) flat directory (with all the files in one pile) should be ignored.

I've added the target directory to .gitignore, but git is still tracking changes in it. I thought if I commit the deletion of the old file in the target directory, git might stop tracking the new contents (copied in by the script), but it doesn't.

How do I make git forget about the target directory?

6 Answers

TL;DR to clean up your git repository and make sure ALL your ignored items are indeed ignored:

git rm -r --cached .
git add .
git commit -m "Clean up ignored files"

Note: you don't need to specify a directory, this way your are cleaning the entire remote repo.

To go further read this

Not sure if this counts or makes me a bad person, but here it goes.

  1. I added *Generated* to the root .gitignore file
  2. I submitted the files I want to keep as GeneratedFile.Whatever.ext.CheckedIn
  3. I made a git hook on post checkout to call a powershell script doing this:

dir *.CheckedIn -Recurse | %{ copy $_.FullName "$($_.FullName)".Replace("CheckedIn","") -EA SilentlyContinue}

I do feel a little bad about myself... but it does in fact work.

Related